Autor Beitrag
O'rallY
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 563



BeitragVerfasst: Mo 16.06.03 17:22 
Ist mir zwar peinlich, aber wie kann man einen string in einen array des Typs char konvertieren?
Das Problem trat im Zusammenhang mit einem TrayIcon auf. Da gibts ja die Variable szTip (array [0..63] of char). Natürlich kann ich ganz leicht schreiben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
szTip := 'text';

//aber sobald eine Varbiable ins Spiel kommt
s: string;
s := 'hallo';
szTip := 'text' + s; //Fehler

Dann habe ich mal probiert jeden Buchstaben einzeln zu übertragen. Misserfolg. Das Array ist anschließend leer:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
newtip: string = 'irgendeintext';

for i := 0 to Length(newtip) - 1 do
    fIconData.szTip[i] := newtip[i];

_________________
.oO'rallY
Linux is like a tipi: No gates, no windows and a gnu-eating apache inside...
ErnestoChe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 528

Win 2000 pro, CRUX 2.0
Delphi 6 Pers, Open K3
BeitragVerfasst: Mo 16.06.03 17:44 
Hi,

also du kanst ein array of Char und einen String verketten und einem anderen String zuweisen, wenn dir das was bringt:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
var
  Form1: TForm1;
  szTip: array[0..63of char;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  s: String;
begin
  szTip := 'Hallo';
  s := ' Welt';
  caption := szTip + s;
end;


MFG

- Ernesto -
O'rallY Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 563



BeitragVerfasst: Mo 16.06.03 17:51 
Ne, das bringt mir leider nix. Ich muss der szTip-Variable eine String zuweisen könne. So schwer kann das doch nicht sein!

_________________
.oO'rallY
Linux is like a tipi: No gates, no windows and a gnu-eating apache inside...
Popov
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1655
Erhaltene Danke: 13

WinXP Prof.
Bei Kleinigkeiten D3Pro, bei größeren Sachen D6Pro oder D7
BeitragVerfasst: Mo 16.06.03 17:56 
Eventuell müßte PChar klappen. Also:

ausblenden Quelltext
1:
szTip := PChar('text' + s); //Fehler					

_________________
Popov
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Mo 16.06.03 18:29 
StrPCopy

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 16.06.03 19:00 
ausblenden Delphi-Quelltext
1:
szTipp := pointer('Test'+s);					
O'rallY Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 563



BeitragVerfasst: Mo 16.06.03 22:36 
Danke für die Antworten. Werde es sobald ich Zeit habe ausprobieren. Motzis und Luckies Beiträge scheinen mir doch vielversprechend zu sein.
Ubrigens: Wer sich die Mühe machen will, jedes Zeichen einzeln zu übertragen:
ausblenden Delphi-Quelltext
1:
2:
3:
newtip: string = 'irgendeintext'
for i := 1 to Length(newtip) do 
    fIconData.szTip[i-1] := newtip[i];

_________________
.oO'rallY
Linux is like a tipi: No gates, no windows and a gnu-eating apache inside...
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Di 17.06.03 02:03 
Was treibt Ihr denn da ? Das geht nur Buchstabe für Buchstabe.

ausblenden Quelltext
1:
2:
for i := 1 to length (s) do
  wasweißich

_________________
Gruß
Hansa
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 17.06.03 08:10 
hansa hat folgendes geschrieben:
Was treibt Ihr denn da ? Das geht nur Buchstabe für Buchstabe.

Erzähl bloß nicht solchen Unsinn! Richtig ist, dass dieser Versuch
ausblenden Delphi-Quelltext
1:
nid.szTip := pchar('Test' + s);					

einen Compiler-Fehler verursacht (zumindest bei mir mit D5). Man kann aber, wie Motzi schrieb, mit StrPCopy arbeiten
ausblenden Delphi-Quelltext
1:
StrPCopy(nid.szTip,'Test' + s);					

bzw. wenn man ohne die SysUtils-Unit auskommen will/muss, dann geht es auch so:
ausblenden Delphi-Quelltext
1:
lstrcpy(nid.szTip,pchar('Test' + s));					
foxy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 814

Ubuntu, Gentoo
C++, PHP, Java, Ruby, Perl (Eclipse)
BeitragVerfasst: Di 17.06.03 08:10 
guter post :) das porblem habe ich auch gerade und wollte gerade topic eröffnen

ich versuch dann gerade mal die vorschläge

_________________
"Only wimps use tape backup: real men just upload their important stuff on ftp, and let the rest of the world mirror it." (Linus Torvalds)
OperatingSystem Laptop (Ubuntu Hardy)