Einzelnen Beitrag anzeigen

Benutzerbild von Amnon82
Amnon82

Registriert seit: 5. Jan 2005
186 Beiträge
 
FreePascal / Lazarus
 
#8

AW: [Linux] String teilen - Trenner Leerzeichen - Anzahl nicht gleich

  Alt 20. Aug 2010, 14:20
Nun hab ichs endlich. Hier die Snippes:

Liste erstellen:

Aufruf bei Programmstart
Delphi-Quellcode:
  //Get Keyboard Variants
  AMemoVariants := TMemo.Create(Form1);
  Processcmd:='xkeyboard-variants';
  Processandwait(Processcmd);
Der ganze Process
Delphi-Quellcode:
//Function ProccessAndWait
procedure Processandwait(Executable : String);
var
  AProcess1: TProcess;
  AStringList: TStringList;
  AMemo: TMemo;
  Result, AString1, AString2 : String;
  i : integer;

begin
  AStringList := TStringList.Create;
  AMemo := TMemo.Create(Form1);
  Result:=' ';
  try
  AProcess1 := TProcess.Create(nil);
  AProcess1.CommandLine := Executable;
  AProcess1.Options := AProcess1.Options+ [poUsePipes];

 {Execute}
  AProcess1.Execute;
  {Wait to finish}
  while AProcess1.running = true do
  begin
       AStringList.LoadFromStream(AProcess1.Output);
       // Fill Keyboard Variants
       if Processcmd = 'xkeyboard-variantsthen
       begin
         AMemoVariants.Lines.add(Astringlist.text);
       end
       else
         AMemo.lines.add(Astringlist.text);
  end;
  finally
    // Fill Keyboard Models
    if Processcmd = 'xkeyboard-modelsthen
    begin
          for i := 0 to AMemo.Lines.Count - 1 do
          if AMemo.lines[i] = 'then
              // do nothing
          else
              Form1.Page2Combobox.items.add(AMemo.lines[i]);
    end;
    // Fill Keyboard Layouts
    if Processcmd = 'xkeyboard-layoutsthen
    begin
          Form1.Page2Layoutlist.clear;
          for i := 0 to AMemo.Lines.Count - 1 do
          if AMemo.lines[i] = 'then
              // do nothing
          else
              begin
                 Astring1:=copy(AMemo.lines[i],0,pos(' ',AMemo.lines[i])-1);
                 AString2:=copy(AMemo.lines[i],pos(' ',AMemo.lines[i])+1,length(AMemo.lines[i]));
                 Form1.Page2Layoutlist.items.add(trim(Astring2) + ' [' + Astring1 + ']');
              end;
    end;
    //Clean up;
    AProcess1.Free;
    AStringlist.Free;
    AMemo.Free;
  end;
end;
Aufruf im Programm
Delphi-Quellcode:
procedure TForm1.Page2LayoutListClick(Sender: TObject);
var
  AString1, AString2 : String;
  i : Integer;
begin
          //Fill Keyboard Variants
          Processvar:= Page2LayoutList.Items.Strings[Page2LayoutList.ItemIndex];
          Processvar:= copy(Processvar,pos('[',Processvar)+1,length(Processvar));
          Processvar:= StringReplace(Processvar,']',':',[rfReplaceAll]);
          Form1.Page2Variantlist.clear;
          Form1.Page2Variantlist.items.add('[None]');
          for i := 0 to AMemoVariants.Lines.Count - 1 do
          if AMemoVariants.lines[i] = 'then
              // do nothing
          else
              if pos(Processvar,AMemoVariants.lines[i]) <> 0 then
              begin
                 Astring1:=copy(AMemoVariants.lines[i],0,pos(' ',AMemoVariants.lines[i])-1);
                 AString2:=copy(AMemoVariants.lines[i],pos(' ',AMemoVariants.lines[i])+1,length(AMemoVariants.lines[i]));
                 AString2:=StringReplace(AString2,Processvar+' ','',[rfReplaceAll]);
                 Form1.Page2Variantlist.items.add(trim(Astring2) + ' [' + Astring1 + ']');
              end;
end;
  Mit Zitat antworten Zitat