2010. március 4., csütörtök

Create a semicolon delimited list of paths


Problem/Question/Abstract:

I'm looking for a component that will build a semicolon delimited list of paths, like the one Delphi presents you to build the include path, etc.

Answer:

No need for a component, just use straight Object Pascal. Example:

procedure TForm1.Button1Click(Sender: TObject);
var
  sList: TStringList;
  i, iRes: integer;
  sTmp: string;
begin
  sTmp := '$(DELPHI)\Lib;$(DELPHI)\Bin;$(DELPHI)\Imports;$(DELPHI)\Projects\Bpl';
  sList := TStringList.Create;
  try
    iRes := Pos(';', sTmp);
    while iRes > 0 do
    begin
      sList.Add(Copy(sTmp, 1, iRes - 1));
      Delete(sTmp, 1, iRes);
      iRes := Pos(';', sTmp);
    end;
    if sTmp <> EmptyStr then
      sList.Add(sTmp);
    showmessage(sList.Text);
    sTmp := '';
    for i := 0 to sList.Count - 1 do
      if i < sList.Count - 1 then
        sTmp := sTmp + sList[i] + ';'
      else
        sTmp := sTmp + sList[i];
    showmessage(sTmp);
  finally
    FreeAndNil(sList);
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése