Autor Beitrag
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Mo 03.03.03 14:33 
Ich habe schon mehrfach Windowsprogramme gesehen, bei denen ein Dateipfad in einem Edit angegeben wurde. Allerdings nicht komplett, sondern so, dass er reinpasste. Also irgendwo mit \...\ drinnen.
Wie kann ich das machen?

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
Maa83
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 160

Win XP Pro
D6 Ent
BeitragVerfasst: Mo 03.03.03 14:59 
tach

kannst du dich mal bitte etwas klarer ausdrücken ich kapier nämlich nicht was du willst :wink:

Zitat:

Allerdings nicht komplett, sondern so, dass er reinpasste


Was soll das denn bitteschön heißen? :shock:
derDoc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Mo 03.03.03 15:32 
Ich habe ein Edit-Feld und schreibe dort einen Dateinamen mit Pfad rein.
Irgendwann ist der Text zu lang und man sieht das Ende mit der Datei nicht mehr.

1. Lösung: Man macht das Edit größer. (Will ich aber nicht!)

2. Lösung: Ich habe es schon häufiger gesehen, dass Programme dann einen Teil aus dem Text herausschneiden und irgendwo im Text mal \...\ auftaucht. Dies soll zeigen, dass es wegen Platzmangel gekürzt wurde. Und genau dafür suche ich eine Lösung.

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
Maa83
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 160

Win XP Pro
D6 Ent
BeitragVerfasst: Mo 03.03.03 15:47 
ahhh... jetzt hab ichs kapiert :)

also wie wärs damit:

du überprüfst während der Eingabe ob eine bestimmte länge erreicht ist (z.B. 30 Zeichen).
Wenn dies der Fall ist durchläufst du den Text nochmal von vorne und kopierst dir den ersten Teil bis zum '\' in eine Variable. Den zweiten Teil + das vorne angehängte \...\ wieder in das Textfeld und lässt den Benutzer weiterschreiben (müsste eigentlich so schnell gehen das der User nichts mitbekommt).

Wenn du nun den Pfad wieder haben möchtest (z.B beim Klick auf einen SaveButton) musst du einfach das Textfeld wieder durchlaufen und überprüfen ob es einen \...\ - Eintrag gibt wenn ja nimmst du die Variable+ den Rest des Textfeldes...

hoffe das ich mich einigermaßen verständlich ausgedrückt habe... ansonsten einfach nachfragen

dann mal ran ans coden :D

gruß
maa
derDoc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Mo 03.03.03 15:56 
Danke für deine Hilfe. Auch wenn ich eigentlich nach einer Funktion gesucht hatte. So wie du es beschreibst kann man das natürlich auch machen.

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
Maa83
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 160

Win XP Pro
D6 Ent
BeitragVerfasst: Mo 03.03.03 16:03 
So ich hab jetzt ein kleines Test-Prog geschrieben jetzt hab ich nur ein Problem:
Wie bekomm ich den Cursor immer an die hinterste Position???

Kann mir da jemand helfen?

ausblenden volle Höhe 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:
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:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    procedure Edit1Change(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
    p1 : String;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Edit1Change(Sender: TObject);
var pfad: String;
    i,tmp : Integer;
    p2 : String;
begin
    pfad := Edit1.Text;
    if length(pfad) > 20 then begin
        for i:=1 to length(pfad) do begin
            if pfad[i] = '\' then tmp := i;
        end;
        p1 := p1+Copy(pfad,1,tmp);
        p2 := Copy(pfad,tmp+1,length(pfad));
        Edit1.Text := '\...\'+p2;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var pfad: String;
    i : Integer;
    tmp: String;
begin
   pfad := Edit1.Text;
   if copy(pfad,1,5) = '\...\' then begin
       tmp := copy(pfad,6,length(pfad));
       pfad := p1+tmp;
   end;
   ShowMEssage(Pfad);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
    p1:='';
end;

end.


Ihr braucht nur einen Button und ein Edit-Feld

stimmt noch nicht alles da ich das gerade mal so hingeschludert hab:)
Maa83
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 160

Win XP Pro
D6 Ent
BeitragVerfasst: Mo 03.03.03 16:12 
ahh jetzt hab ichs also so klappts:

ausblenden volle Höhe 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:
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:
65:
66:
67:
68:
69:
70:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    procedure Edit1Change(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
    p1 : String;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Edit1Change(Sender: TObject);
var pfad: String;
    i,tmp : Integer;
    p2 : String;
begin
    pfad := Edit1.Text;
    if length(pfad) > 20 then begin
        for i:=1 to length(pfad) do begin
            if pfad[i] = '\' then tmp := i;
        end;
        if p1 <> '' then
            p1 := p1+Copy(pfad,6,tmp)
        else p1 := p1+Copy(pfad,1,tmp);

        p2 := Copy(pfad,tmp+1,length(pfad));
        Edit1.Text := '\...\'+p2;
        Edit1.SetFocus;
        Edit1.SelStart := length(edit1.Text);
        edit1.SelLength := 0;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var pfad: String;
    i : Integer;
    tmp: String;
begin
   pfad := Edit1.Text;
   if copy(pfad,1,5) = '\...\' then begin
       tmp := copy(pfad,6,length(pfad));
       pfad := p1+tmp;
   end;
   ShowMessage(Pfad);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
    p1:='';
end;

end.
derDoc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Mo 03.03.03 20:22 
Also wenn ich dein Programm richtig verstehe, setzt das beim Eingeben in das Edit Feld alle 20 Zeichen den Anfang auf \...\. Ich hatte eigentlich vor, irgendwo in diesem Pfad sowas einzubauen.

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Mo 03.03.03 20:48 
*lol* Klar...warum einfach wenns auch kompliziert geht.

Die Function, die du suchst heisst: PathCompactPath!

PathCompactPath(Edit1.Canvas , FilePath , Edit1.width, cpCenter);

viel spass!
Maa83
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 160

Win XP Pro
D6 Ent
BeitragVerfasst: Mo 03.03.03 21:19 
Buhuhu :cry:
verjag mich doch gleich...
Jetzt hab ich mir doch sooooo viel Mühe gegeben... MUHU :D

aber mir fällt immer wieder auf das Delphi tausende von nützlichen Funktionen hat die ich nicht kenne... ich code mich zu tode und plötzlich kommt mein Kumpel und lacht sich halb tot und schreibt eine Zeile Code mit einer blöden Delphi - Funktion... :shock:

Bis morgen bin ich jetzt gefrustet

gut nacht wünsch ich allen

Maa
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Mo 03.03.03 23:47 
Aooch...nich traurig sein :D

Das is uns allen schon passiert, denke ich. Manchmal geht es schneller die funktion zu schreiben, als sie zu finden.

bis denn.
maximus.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 03.03.03 23:55 
Da hätte ich auch noch einen:
ausblenden volle Höhe 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:
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:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
***************************************************************************}
{                                                                              }
{                        Delphi-Unit DotPath V1.0                              }
{                                                                              }
{                    Copyright (c) 2001 Michael Puff                           }
{                          www.luckie-online.de                                }
{                                                                              }
{******************************************************************************}

{ What it does...
  Diese Unit verkürzt einen lange Dateipfad zu einem kurzen mit Pünktchen,
  wobei man die Anzahl der Backslashes angeben kann die von vorne bzw. von hinten
  angezeigt werden sollen

  Beispiel:
  macht aus:
  E:\Michael\eigene Dateien\Programmierung\Delphi\Programme\VCL\in Bearbeitung\MichaelsMusikDB02.zip
  mit den Einstellungen 2 Backslashes von vorne und 2 von hinten das:
  E:\Michael\...\in Bearbeitung\MichaelsMusikDB02.zip

  How to use this garbage of code...
  Einfach die Unit in die Uses-Klausel aufnehmen und
  DotPath.ShortPath(Path, 2, 2);
  ergibt obiges Ergebnis, wenn Path der oben genannte Beispiel-Pfad ist
}



unit DotPath;

interface
  function ShortPath(Path: String; NumSlashesBegin, NumSlashesEnd: Byte): String;
  function CountBackSlashes(Path: String): Integer;


implementation

uses windows;

{ für so ein bißchen keine SysUtils }
function ExtractFileName(const FileName: string): string;
var
   RPos: Integer;
begin
   RPos := Length(FileName);
   while not (FileName[RPos] in ['\', ':']) and (RPos > 0) do
      Dec(RPos);
   Result := Copy(FileName, RPos + 1, MaxInt);
end;

function ExtractFilePath(const FileName: string): string;
var
   RPos: Integer;
begin
   RPos := Length(FileName);
   while not (FileName[RPos] in ['\', ':']) and (RPos > 0) do
      Dec(RPos);
   Result := Copy(FileName, 0, RPos);
end;

function CountBackSlashes(Path: String): Integer;
var
  i: byte;
  cBackSlash: Byte;  { Anzahl der BackSlashes }
begin
  { Anzahl der BackSlashes ermitteln }
  cBackSlash := 0;
  for i := 0 to length(Path) do
  begin
    if Path[i] = '\' then
      Inc(cBackSlash);
  end;
  result := cBackSlash;
end;

function ShortPath(Path: String; NumSlashesBegin, NumSlashesEnd: Byte): String;
{ Path: na was wohl ;))
{ NumSlashes: Anzal der "\"-Dinger, die angezeigt werde sollen bevor die
  Pünktchens kommen }
var
  i, j: byte;
  aBackSlash: array of Byte;  { Array für die BackSlashes und deren Position }
  ShortPath: String; { gekürzter Pfad }
  Temp: String;
  FileName: String;
begin
  { Nur mal kucken, ob da keiner Blödsinn eingibt }
  if (NumSlashesBegin > CountBackSlashes(Path)) or
    (NumSlashesEnd > CountBackSlashes(Path))then
  begin
    result := Path;
    exit;
  end;
  if (NumSlashesEnd > CountBackSlashes(Path)) or
    (NumSlashesEnd > CountBackSlashes(Path))then
  begin
    result := Path;
    exit;
  end;

  { Eingaben korrigieren }
  if CountBackSlashes(Path) <= 3 then
  begin
    result := Path;
    exit;
  end;
  if NumSlashesBegin = 0 then NumSlashesBegin := 1;
  if NumSlashesEnd = 0 then NumSlashesEnd := 1;

  { Größe des BackSlash-Arrays setzen }
  SetLength(aBackSlash, CountBackSlashes(Path));

  { BackSlash-Array mit den Positionen der BackSlashes füllen }
  j := 0;
  for i := 0 to length(Path) do
  begin
    if Path[i] = '\' then
    begin
      aBackSlash[j] := i;
      Inc(j);
    end;
  end;

  ShortPath := copy(Path, 0, aBackSlash[NumSlashesBegin-1]-1);
  Temp := copy(Path, abackSlash[CountBackSlashes(Path)-NumSlashesEnd],
    length(ExtractFilePath(Path)));
  FileName := ExtractFileName(Path);

  result := ShortPath + '\...' + Temp;
end;

end.
Wolff68
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 302
Erhaltene Danke: 1

WinXP home
D6 Prof
BeitragVerfasst: Di 04.03.03 05:39 
Siehste Maa83,
Auch andere haben sich die Mühe gemacht und sowas selber gecoded obwohl es sowas schon gibt. :D
Also nicht gefrustet sein, wenn Du mal was schreibst was es schon gibt.
Dafür weist Du dann auch wie es funktioniert.

_________________
"Der Mensch ist nicht was er sich vorstellt oder wünscht zu sein, sondern das was andere in ihm sehen."
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 04.03.03 05:43 
Bei mir hatte das bloß den Hintergrund, dass ich die SysUtils nicht einbinden wollte wegen der einen Funktion.
Popov
Gast
Erhaltene Danke: 1



BeitragVerfasst: Di 04.03.03 11:46 
@derDoc

Versuch das mal:

ausblenden Quelltext
1:
2:
3:
4:
uses 
  ..., FileCtrl; 

with Label1 do Caption := MinimizeName(ParamStr(0), Canvas, Width);


ungeprüft
derDoc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Di 04.03.03 13:38 
Ich werde eure Vorschläge mal testen, und schreiben, welcher mir am meisten hilft.

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.