Autor Beitrag
NoVeK
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 20



BeitragVerfasst: Mi 22.12.04 20:37 
Ich lese aus der Registry den Pfad aus aus und deklariere diesen in einem Pfad!

So hat man dann in einem String z.b. : C:\Programme\bProgramm\programm.exe als Wert eingetragen.

Nun will ich wenn man mein Programm startet das immer der in der StingVariable stehende Pfad (mit Exe Datei angegeben) per Shellexecute ausführt wird. Dies hab ich dann so geschrieben.


ShellExecute(Application.Handle, 'open', pfadvariable , nil, nil, SW_SHOW);

Doch leider kommt dann immer die Meldung: Inkompatible Typen Sting und PAnsiChar.

Was kann ich tun, wie lautet der Pfad richtig?
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Mi 22.12.04 21:24 
Hi, ich weiß im Moment auch net, woran das liegen könnte... :cry:

Es gibt aber eine Funktion in der FMXUtils.pas (Bsp.: C:\Programme\Borland\Delphi\Demos\Doc\Filmanex\FMXUtils.pas) die ExecuteFile heißt. An diese Funktion übergibt man Strings. Das funzt auf jeden Fall.

Ich guck mal nach wie die das da machen (die benutzen da glaub' ich auch ShellExecute).

mfG, WeBsPaCe
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Mi 22.12.04 21:28 
Also, in der FMXUtils steht für die Funktion ExecuteFile folgendes:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
function ExecuteFile(const FileName, Params, DefaultDir: string;
  ShowCmd: Integer): THandle;
var
  zFileName, zParams, zDir: array[0..79of Char;
begin
  Result := ShellExecute(Application.MainForm.Handle, nil,
    StrPCopy(zFileName, FileName), StrPCopy(zParams, Params),
    StrPCopy(zDir, DefaultDir), ShowCmd);
end;


Wenn du das in deinem eigentlichen Programm benutzt, sollte es funktionieren...

mfG, WeBsPaCe
chrisdrury
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 184

WinXP
D5 Prof
BeitragVerfasst: Do 23.12.04 08:48 
Wie wäre es, den Pfad mit PChar umzuwandeln?
Also bei mir funzt das:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
  try
    Browser := FindRegPath('IEXPLORE.EXE');
  finally
    if Browser = '' then ShowMessage('Der Internet-Explorer konnte nicht gefunden werden!');
  end;
  try
    if ShellExecute(Self.Handle, 'Open', PChar(Browser), PChar(Pathname), ''1) <= 32 then
      ShowMessage('Fehler beim Browserstart!');
  except
  end;

Dabei ist Browser eine Stringvariable, in der der Pfad zum Internet-Explorer (aus der Registry ausgelesen) steht und Pathname der entsprechende Pfad der anzuzeigenden Datei.

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Do 23.12.04 14:33 
Jop, so geht's natürlich auch, aber ist das nicht genau das was in der
ausblenden Delphi-Quelltext
1:
ExecuteFile();					

passiert?? :? :? :?
NoVeK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 20



BeitragVerfasst: Fr 24.12.04 02:49 
Âlso ich komm jetzt irgendwie nicht, es wäre schön wenn ihr mir sagen könntet was ich genau machen muss. Also hier sieht ihr wie die variable gefüllt wird. Beim tspfad handelt sich es um den Pfad zur Datei.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
begin
reg:=Tregistry.Create;
reg.RootKey:=HKEY_CURRENT_USER;
reg.OpenKey('Software\Programmlein\1.0',true);
if reg.ValueExists('tspfad'then begin
try
tsrun := reg.ReadString('tspfad');
except
showmessage('ERROR: Code:r002s');
end;


Nun will ich das tsrun in einem shellexecute ausgeführt wird. Wäre schön wenn ihr alles erwähnt... users. functions, vars usw...

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Fr 24.12.04 03:13 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm1.Button1Click(Sender: TObject);
const
  S_TSPFAD = 'tspfad';
begin

  with TRegistry.Create do
  begin
    try
      RootKey := HKEY_CURRENT_USER;
      if OpenKeyReadOnly('Software\Programmlein\1.0'then
        if ValueExists(S_TSPFAD) then
          if GetDataType(S_TSPFAD) = rdString then
            ShellExecute(GetDesktopWindow, 'open', PChar(ReadString(S_TSPFAD)), nilnil, SW_SHOW);
    finally
      Free;
    end;
  end;

end;

_________________
Ciao, Sprint.