Autor Beitrag
PeterKiers
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26


D7
BeitragVerfasst: Fr 19.01.07 17:21 
Hallo!
hab mal Folgende Frage

Mit dieser Funktion können Lange Pfade in kurtze umgewandelt werden:

ausblenden 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:
uses 
  Windows, SysUtils; 

function GetShortName(sLongName: string): string; 
var 
  sShortName:    string;
  nShortNameLen: Integer; 
begin 
  SetLength(sShortName, MAX_PATH); 
  nShortNameLen := GetShortPathName(PChar(sLongName), PChar(sShortName), MAX_PATH - 1);
  if (0 = nShortNameLen) then 
  begin 
    // handle errors... 
  end; 
  SetLength(sShortName, nShortNameLen); 
  Result := sShortName; 
end; 

// Example: 

procedure TForm1.Button1Click(Sender: TObject); 
begin 
  Caption := GetShortName('C:\Program Files\Delphi6\Lib\test.cnt'); 
  // --> C:\PROGRA~1\Delphi6\Lib\test.cnt 
end;


meinen code:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
function GetShortName(sLongName: string): string;
var
  sShortName:    string;
  nShortNameLen: Integer;
begin
  SetLength(sShortName, MAX_PATH);
  nShortNameLen := GetShortPathName(PChar(sLongName), PChar(sShortName), MAX_PATH - 1);
  if (0 = nShortNameLen) then
  begin
    // handle errors...
  end;
  SetLength(sShortName, nShortNameLen);
  Result := sShortName;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Caption := GetShortName(Edit1.Text);
end;



Es funktioniert nicht. Was mach ich falsch?

Hoffe ihr könnt mir helfen und danke schonmal im Voraus.

Peter kiers

Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 19.01.07 17:27 
Was funktioniert denn nicht? Passiert gar nix, oder kommt ein Fehler, oder was?
PeterKiers Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26


D7
BeitragVerfasst: Fr 19.01.07 17:56 
Ich habe es so gemacht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject);
var d:TOpendialog;
begin
  d:=TOpendialog.Create(self);
  d.Execute;
  caption := d.FileName;
  d.free;
end;


Bei Caption:

C:\Documents and Settings\HP_Eigenaar\Bureaublad\Test.doc

Dass ist doch nich kurtz!

Peter

Moderiert von user profile iconmatze: Code- durch Delphi-Tags ersetzt
PeterKiers Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26


D7
BeitragVerfasst: Fr 19.01.07 18:09 
Ich habe es schon

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject); 
var d:TOpendialog; 
begin 
d:=TOpendialog.Create(self); 
d.Execute; 
Caption := GetShortName(d.FileName); 
d.free; 
end;


Danke fur die Hilfe.

Peter Kiers

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt