Autor Beitrag
Wolle92
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Sa 08.09.07 09:29 
Hallo,
Ich wüsste gerne, wie ich Teilstrings eines PChar-Strings in einen anderen kopieren kann...
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Sa 08.09.07 10:55 
Auf Anhieb würde ich den PChar nach String casten und dann mit Pos und Copy arbeiten.

_________________
We are, we were and will not be.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Sa 08.09.07 10:59 
StrLCopy könnte hilfreich sein.
In der Hilfe von Delphi findest Du unter String-Verarbeitung (nullterminiert) noch ein ganze Menge mehr Funktionen.
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Sa 08.09.07 11:05 
Mit StrLCopy kann man aber nur einen Teilstring am Anfang kopieren... das will ich aber nicht
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Sa 08.09.07 11:11 
Hast Du Dir die weiteren Funktionen mal angesehen (z.B. StrMove)? Du musst als "Source" ja nicht am Anfang des "alten" Strings anfangen. :wink:

Ansonsten solltest Du Gausis Rat befolgen. Wenn ich nicht zwingend mit PChar arbeiten muss, arbeite ich oft genauso.
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Sa 08.09.07 13:14 
Kann man denn in DLLs Strings benutzen, wenn die nicht nach außen gebracht werden?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 08.09.07 13:51 
Ja, kann man, Probleme bekommst du nur, wenn du Strings als Parameter oder Rückgabewerte von exportierten Funktionen benutzt, die du dann also von außerhalb aufrufst. Innerhalb der DLL kannst du alles ganz normal nutzen (ohne ShareMem und die DLL natürlich ;-)).
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Sa 08.09.07 14:52 
Aha, ok, aber kannst du mir erklären, wieso diese funktionsweise nicht funktioniert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
function decode(text: PChar): PChar; export;
var current, text2, result2: String;
begin
  result2 := '';
  text2 := String(text);
  while not (text2 = ''do
  begin
    current := Copy(text2,1,Pos('z',text2)-1);
    text2 := Copy(text2,Pos('z',text2)+1,Length(text2)-Pos('z',text2));
    result2 := result2 + Chr(Byte(StrtoInt(current)));
  end;
  result := PChar(result2);
end;

Wenn ich aber vor current := Copy(text2,1,Pos('z',text2)-1); ein beliebiges ShowMessage setze, alles einwandfrei funktioniert?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 13.09.07 00:16 
Tut mir leid, ich hatte den Thread aus den Augen verloren, deshalb die späte Antwort.

Was passiert denn? Ich meine, ich kann das auch einfach mal ausprobieren, aber das kannst du ja eigentlich auch gleich selbst sagen.