Mark
Yeah, I sort of thought you might want to actually extract the column data
Here are a couple of primative routines that I use to extract delim items
from a string
(You could also use ExtractFieldName function in the DB unit)
Prob has less overhead and flexibility thatn using commatext of a stinglist
the GetStrCell can be used as a loop ie
I := 0
while GetStrCell(S,I,C';') do begin
// process C here
inc(I)
end
function GetStrCell(AString: string; ACol: Integer; var AStrResult: string;
Sep: char): Boolean;
var
Col, StartPos, i: Integer;
begin
AStrResult := '';
Result := False;
StartPos := 1;
Col := -1;
for i := 1 to Length(AString) do
begin
if AString[i] = Sep then
begin
Inc(Col);
if Col <> ACol then StartPos := i+1
else
begin
AStrResult := Copy(AString, StartPos, i - StartPos);
Result := True;
Break;
end;
end;
end;
if (i >= Length(AString)) and (Length(AString) > 0) and (Col+1 = ACol)
then
begin
AStrResult := Copy(AString, StartPos, Length(AString) - StartPos + 1);
Result := True;
end;
end;
procedure SetStrCell(var AString: String; ACol: Integer; ANewStr: String);
var
Col, StartPos, i: Integer;
begin
StartPos := 1;
Col := -1;
i := 1;
while i <= Length(AString) do
begin
if AString[i] = DefSep then
begin
Inc(Col);
if Col <> ACol then StartPos := i+1
else
begin
Delete(AString, StartPos, i - StartPos);
Insert(ANewStr, AString, StartPos);
Break;
end;
end;
Inc(i);
end;
if (i > Length(AString)) then
begin
while (Col+1 < ACol) do
begin
AString := AString + DefSep;
StartPos := Length(AString)+1;
Inc(Col);
end;
Delete(AString, StartPos, Length(AString) - StartPos + 1);
Insert(ANewStr, AString, StartPos);
end;
end;
----- Original Message -----
From: "Mark Howard" <[EMAIL PROTECTED]>
To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]>
Sent: Friday, November 08, 2002 11:31 AM
Subject: Re: [DUG]: Multi-column String List?
> Neven
>
> Not exactly what I was after :-(
>
> I have implemented the following (where SL is a Stringlist in the
> Names=Values format you suggested), but would be interested if a
> variant of your method could do the same more efficiently.
>
> function GetValue(Entry: String; col: Integer): String;
> var StRec: TstringList;
> begin
> try
> StRec := TStringList.Create;
> StRec.CommaText := SL.Values[Entry];
> Result := StRec[col];
> finally
> StRec.Free;
>
> Mark
> end;
> end;
>
> On 8 Nov 2002 at 11:00, Neven MacEwan wrote:
>
> > Mark
> >
> > Sorry I coded it as a Method (hence Self is the TStringList)
> >
> > as a function
> >
> > function GetValue(Strings: TStringList; Index: integer): string;
> > begin
> > Result := copy(Strings[Index],pos('=',Strings[Index])+1,MaxInt)
> > end;
> >
> >
> > N
> >
> >
> > ----- Original Message -----
> > From: "Mark Howard" <[EMAIL PROTECTED]>
> > To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]>
> > Sent: Friday, November 08, 2002 10:35 AM
> > Subject: Re: [DUG]: Multi-column String List?
> >
> >
> > > Sorry, not trivial enough for me.
> > > I can't figure out how to call it - 'Self' is putting me off.
> > >
> > > Mark
> > >
> > > On 7 Nov 2002 at 16:46, Neven MacEwan wrote:
> > >
> > > > No
> > > >
> > > > but what you are asking is trivial
> > > >
> > > > function GetValue(Index: integer): string;
> > > > begin
> > > > Result := copy(Self[Index],pos('=',Self[Index])+1,MaxInt)
> > > > end;
> > > >
> > > > Neven
> > > >
> > > > ----- Original Message -----
> > > > From: "Mark Howard" <[EMAIL PROTECTED]>
> > > > To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]>
> > > > Sent: Thursday, November 07, 2002 4:34 PM Subject: Re: [DUG]:
> > > > Multi-column String List?
> > > >
> > > >
> > > > > Neven
> > > > >
> > > > > Can Values be an enumerated list? ie can you refer
> > > > > to Values[i]?
> > > > > Couldn't see any reference to that in Help.
> > > > >
> > > > > Mark
> > > > >
> > > > > On 7 Nov 2002 at 15:10, Neven MacEwan wrote:
> > > > >
> > > > > > Mark
> > > > > >
> > > > > > You could use a std string list with the 'name' and 'values'
> > > > > > properties
> > > > > >
> > > > > > Entry_Field=Col1,Col2,Col3.... etc
> > > > > >
> > > > > > Beyond that I'd look at kbmMemTable
> > > > > >
> > > > > > HTH
> > > > > >
> > > > > > Neven
> > > > > >
> > > > > > ----- Original Message -----
> > > > > > From: "Mark Howard" <[EMAIL PROTECTED]>
> > > > > > To: "Multiple recipients of list delphi"
> > > > > > <[EMAIL PROTECTED]> Sent: Thursday, November 07, 2002 3:00
> > > > > > PM Subject: [DUG]: Multi-column String List?
> > > > > >
> > > > > >
> > > > > > > Hi all
> > > > > > >
> > > > > > > I want a very simple way to load and access a small lookup
> > > > > > > table from a comma delimited text file.
> > > > > > >
> > > > > > > What would be ideal would be an implementation of a multi
> > > > > > > column string list that would allow: LoadFromFile and access
> > > > > > > to a particular row of columns to the right of #1 using
> > > > > > > Items.IndexOf('Entry_Field') to determine the row
> > > > > > >
> > > > > > > I feel sure there must be something simple available.
> > > > > > >
> > > > > > > TIA
> > > > > > >
> > > > > > > Mark
> > > > > > > ------------------------------------------------------------
> > > > > > > ---- ---- ------
> > > > > > -
> > > > > > > New Zealand Delphi Users group - Delphi List -
> > > > > > > [EMAIL PROTECTED]
> > > > > > > Website: http://www.delphi.org.nz
> > > > > > > To UnSub, send email to: [EMAIL PROTECTED]
> > > > > > > with body of "unsubscribe delphi"
> > > > > > > Web Archive at:
> > > > > > > http://www.mail-archive.com/delphi%40delphi.org.nz/
> > > > > > >
> > > > > >
> > > > > > --------------------------------------------------------------
> > > > > > ---- ---- -----
> > > > > > New Zealand Delphi Users group - Delphi List -
> > > > > > [EMAIL PROTECTED]
> > > > > > Website: http://www.delphi.org.nz
> > > > > > To UnSub, send email to: [EMAIL PROTECTED]
> > > > > > with body of "unsubscribe delphi"
> > > > > > Web Archive at:
> > > > > > http://www.mail-archive.com/delphi%40delphi.org.nz/
> > > > > >
> > > > >
> > > > >
> > > > > ----------------------------------------------------------------
> > > > > ---- ------
> > > > -
> > > > > New Zealand Delphi Users group - Delphi List -
> > > > > [EMAIL PROTECTED]
> > > > > Website: http://www.delphi.org.nz
> > > > > To UnSub, send email to: [EMAIL PROTECTED]
> > > > > with body of "unsubscribe delphi"
> > > > > Web Archive at:
> > > > > http://www.mail-archive.com/delphi%40delphi.org.nz/
> > > > >
> > > >
> > > > ------------------------------------------------------------------
> > > > ---- -----
> > > > New Zealand Delphi Users group - Delphi List -
> > > > [EMAIL PROTECTED]
> > > > Website: http://www.delphi.org.nz
> > > > To UnSub, send email to: [EMAIL PROTECTED]
> > > > with body of "unsubscribe delphi"
> > > > Web Archive at:
> > > > http://www.mail-archive.com/delphi%40delphi.org.nz/
> > > >
> > >
> > >
> > > --------------------------------------------------------------------
> > > ------
> > -
> > > New Zealand Delphi Users group - Delphi List -
> > > [EMAIL PROTECTED]
> > > Website: http://www.delphi.org.nz
> > > To UnSub, send email to: [EMAIL PROTECTED]
> > > with body of "unsubscribe delphi"
> > > Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
> > >
> >
> > ----------------------------------------------------------------------
> > -----
> > New Zealand Delphi Users group - Delphi List -
> > [EMAIL PROTECTED]
> > Website: http://www.delphi.org.nz
> > To UnSub, send email to: [EMAIL PROTECTED]
> > with body of "unsubscribe delphi"
> > Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
> >
>
>
> --------------------------------------------------------------------------
-
> New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
> Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED]
> with body of "unsubscribe delphi"
> Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
>
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/