You could simplify your CreateAddress procedure to look like this
procedure createAddress(aQuery: TQuery; aList: TStringList);
var
i: Integer;
begin
aList.Clear;
for i := 0 to aQuery.RecordCount - 1 do
if (aQuery.Fields[i].AsString <> '') then
aList.Add(aQuery.Fields[i].AsString)
end;
What database and what report components are you using? If your database
supports stored procedures why don't you write a stored procedure that does
return a cursor containing a single field called Address which is the
concatenation of all the non null address fields from your address table.
From what I understood is that you first run a query, then scan this
query to retrieve the values of its fields and move them to another data
structure right? Too much work in my opinion.
There might be much better ways to handle this issue, whatever are the
report components that you are using, they will have some kind of Label
component. On the OnGetText or OnPrint (depending of the component) event of
that control you might want to write the procedure I have written above, but
instead of assigning values to a string list, you will assign directly to
the text of the label. Remember that when you have assigned a dataset to a
report and this report is in printing process, datasets records are already
scanned from top to bottom on each new line of the report to retrieve data
and print. So you might want to do the job then instead of running a query,
scanning it to retrieve data from it, pass it to the report which will scan
the query on its turn another time, etc...
Hope this helps
Vahan
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] Behalf
Of petesouthwest
Sent: Tuesday, October 18, 2005 10:06 PM
To: [email protected]
Subject: [delphi-en] dynamic structures of tstringlist? Tlist?
Hi
I have a database that has records with 8 fields relating to the
address. Any one of these fields could be empty/blank. When I generate
my reports I need the address to print without the blanks. For example
if the county has been left blank:
1 Kings Street
Morden
SM4 5DF
Should look like:
1 Kings Street
Morden
SM4 5DF
Unfortunatly the reporting components I'm using cant automatically do
this :(
I thought i had overcome the problem by creating a global string list
and adding non blank lines, ie using the procedure createAddress shown
below.
I can then use the tstringlist values by passing them as variables to
the report, using a procedure that runs as the report is created
containing code such as:
if CompareText(VarName, 'line1') = 0 then
value:=addresslist.address[0];
This is fine for one report! :(
However, I need this to be done for any number records. Therefore I
need some form of dynamic data structure that can contain a
tstringlist for each record.
I have looked at tlist and assume I can do something like:
addresslist:=tlist.Create;
while not qryMailinglist.Eof do
begin
Address:= TStringList.Create;
createAddress(address);
addresslist.Add(address)
end;
but cant get my head around the syntax I would need to access each
stringlist.
Any comments on better ways, or how to access the values appreciated :)
Many thanks
Pete
procedure createAddress
begin
if (qryMailingList.fieldbyname('ADDRESS1').asstring<>'') then
address.Add(qryMailingList.fieldbyname('ADDRESS1').asstring);
if (qryMailingList.fieldbyname('ADDRESS2').asstring<>'') then
address.Add(qryMailingList.fieldbyname('ADDRESS2').asstring);
if (qryMailingList.fieldbyname('ADDRESS3').asstring<>'') then
address.Add(qryMailingList.fieldbyname('ADDRESS3').asstring);
if (qryMailingList.fieldbyname('ADDRESS4').asstring<>'') then
address.Add(qryMailingList.fieldbyname('ADDRESS4').asstring);
if (qryMailingList.fieldbyname('TOWN').asstring<>'') then
address.Add(qryMailingList.fieldbyname('TOWN').asstring);
if (qryMailingList.fieldbyname('COUNTY').asstring<>'') then
address.Add(qryMailingList.fieldbyname('COUNTY').asstring);
if (qryMailingList.fieldbyname('COUNTRY').asstring<>'') then
address.Add(qryMailingList.fieldbyname('COUNTRY').asstring);
if (qryMailingList.fieldbyname('POSTCODE').asstring<>'') then
address.Add(qryMailingList.fieldbyname('POSTCODE').asstring);
end;
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
SPONSORED LINKS Basic programming language C programming language Computer
programming languages
The c programming language C programming language List of
programming languages
----------------------------------------------------------------------------
----
YAHOO! GROUPS LINKS
a.. Visit your group "delphi-en" on the web.
b.. To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
----------------------------------------------------------------------------
----
[Non-text portions of this message have been removed]
------------------------ Yahoo! Groups Sponsor --------------------~-->
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/i7folB/TM
--------------------------------------------------------------------~->
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/delphi-en/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/