| Autor |
Beitrag |
Blamaster
      
Beiträge: 164
|
Verfasst: Mo 03.09.07 15:36
Hi,
wie kann ich eine variabele die nach einer 1 Klick Funktion mit Inhalt gefüllt wird in eine Funktion einfügen so, das dort auch Inhalt ausgegeben wird.
Eein Beispielcode:
Funktion:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64:
| function ExecConsole(var Output, Errors: String): Boolean; var StartupInfo: TStartupInfo; ProcessInfo: TProcessInformation; SecurityAttr: TSecurityAttributes; PipeOutputRead, PipeOutputWrite, PipeErrorsRead, PipeErrorsWrite: THandle;
function ReadPipeToString(const hPipe: THandle): String; const MEM_CHUNK_SIZE = 8192; var NumberOfBytesRead, NumberOfBytesTotal: Cardinal; begin Result := ''; NumberOfBytesTotal := 0; repeat SetLength(Result,Length(Result) +MEM_CHUNK_SIZE); if ReadFile(hPipe,(@Result[1+NumberOfBytesTotal])^,MEM_CHUNK_SIZE, NumberOfBytesRead,NIL) then Inc(NumberOfBytesTotal,NumberOfBytesRead); SetLength(Result,NumberOfBytesTotal); until (NumberOfBytesRead = 0); end;
begin FillChar(ProcessInfo,SizeOf(TProcessInformation),0); FillChar(SecurityAttr,SizeOf(TSecurityAttributes),0); SecurityAttr.nLength := SizeOf(SecurityAttr); SecurityAttr.bInheritHandle := TRUE; SecurityAttr.lpSecurityDescriptor := NIL; CreatePipe(PipeOutputRead,PipeOutputWrite,@SecurityAttr,0); CreatePipe(PipeErrorsRead,PipeErrorsWrite,@SecurityAttr,0); FillChar(StartupInfo,SizeOf(TStartupInfo),0); StartupInfo.cb := SizeOf(StartupInfo); StartupInfo.hStdInput := 0; StartupInfo.hStdOutput := PipeOutputWrite; StartupInfo.hStdError := PipeErrorsWrite; StartupInfo.wShowWindow := SW_SHOW; StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES; Result := CreateProcess(NIL,PChar('C:\Programme\WinRAR\rar.exe e -p' + pwid + '' + 'C:\Downloads\make_u_more.rar C:\Downloads\make_u_more\'),NIL,NIL,TRUE, CREATE_DEFAULT_ERROR_MODE or CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, NIL,NIL,StartupInfo,ProcessInfo);
CloseHandle(PipeOutputWrite); CloseHandle(PipeErrorsWrite); if (Result) then begin Output := ReadPipeToString(PipeOutputRead); Errors := ReadPipeToString(PipeErrorsRead); WaitForSingleObject(ProcessInfo.hProcess,INFINITE); CloseHandle(ProcessInfo.hProcess); end; CloseHandle(PipeOutputRead); CloseHandle(PipeErrorsRead); end; |
1 Klick Procedur:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
| procedure TForm1.Button2Click(Sender: TObject); begin try ini:=TIniFile.create(ExtractFilePath(ParamStr(0))+'einstellungen.ini'); Pwcheck:= ini.ReadInteger('Optionen','Id',-1); finally ini.free; end; try if ExecConsole(Output,Errors) then begin if (Errors <> '') then begin Pwid:=(Listbox1.Items[Pwcheck + 1]); try ini:=TIniFile.create(ExtractFilePath(ParamStr(0))+'einstellungen.ini'); ini.WriteInteger('Optionen','Id',Pwcheck + 1); finally ini.free; end; ShowMessage(Pwid); end; end else ShowMessage('Befehl konnte nicht ausgeführt werden: '); finally
end; end; |
Nach dem Klick auf den button soll der Inhalt der variabele Pwid dort hin kommen:
Delphi-Quelltext 1: 2: 3: 4: 5: 6:
| Result := CreateProcess(NIL,PChar('C:\Programme\WinRAR\rar.exe e -p' + <span style="color: red">pwid</span> + '' + 'C:\Downloads\make_u_more.rar C:\Downloads\make_u_more\'),NIL,NIL,TRUE, CREATE_DEFAULT_ERROR_MODE or CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, NIL,NIL,StartupInfo,ProcessInfo); |
|
|
fuba
      
Beiträge: 125
Win7
D7 Ent.
|
Verfasst: Mo 03.09.07 20:10
ich würd mal sagen, indem du ne globale Variable setzt oder eine Variable im "Private" abschitt, falls diese Fromübergreifend sein soll.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;
type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private pwidglobal: string; public end;
var Form1: TForm1; pwid: string; implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject); begin end;
end. |
wenn du die Form-übergreifende variante nimmst, brauchst du dann nur im Form2 z.b dies machen:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32:
| unit Unit2;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;
type TForm2 = class(TForm) procedure FormCreate(Sender: TObject); private public end;
var Form2: TForm2;
implementation
uses Unit1;
{$R *.dfm}
procedure TForm2.FormCreate(Sender: TObject); begin Caption:=Form1.pwidglobal; end;
end. |
hoffe ich habe dich da richtig verstanden 
|
|
Sinspin
      
Beiträge: 1338
Erhaltene Danke: 120
Win 10
RIO, CE, Lazarus
|
Verfasst: Mo 03.09.07 20:21
Deine Procedure bekommt doch schon zwei Parameter. (hier sind es ja eigentlich Antworten)
Schreibe doch den dritten Parameter, dein Passwort, einfach dahinter:
Delphi-Quelltext 1:
| function ExecConsole(var Output, Errors: String; const pwid: String): Boolean; |
_________________ Wir zerstören die Natur und Wälder der Erde. Wir töten wilde Tiere für Trophäen. Wir produzieren Lebewesen als Massenware um sie nach wenigen Monaten zu töten. Warum sollte unser aller Mutter, die Natur, nicht die gleichen Rechte haben?
|
|
GTA-Place
      

Beiträge: 5248
Erhaltene Danke: 2
WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
|
Verfasst: Mo 03.09.07 21:27
Das kann aber alles nicht funktionieren, da er PWId erst nach dem Aufruf der Funktion einen Wert zuweist 
_________________ "Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
|
|
Blamaster 
      
Beiträge: 164
|
Verfasst: Mo 03.09.07 21:32
@ Gta Place: Genau das ist mein Problem
Hast du oder jemand ne Idee wie man das lösen könnte ?
Edit. Hab die function jetzt einfach in die button1klick procedur reingesetzt.
|
|
|