Autor Beitrag
rubooo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52

WIN XP
Delphi 2005 Prof
BeitragVerfasst: Sa 07.05.05 15:49 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Button1Click(Sender: TObject);
var a: Char; zeilennr: array[1..66of Integer;
begin
  a := ['a'];
  if Edit1.Text[zeilennr] in a then
    Edit2.Text := '1'
  else
    ShowMessage('Fehler!');
end;


wenn ich diesen Code aber nun compilieren will dann spuck mir Delphi das aus ::

Zitat:
Incompatible Types: 'Integer' and 'Array'!


Kann ich das trotzdem irgendwie hinbekommen das es läuft?
oder kann ich anders angeben wenn ein 'a' in edit1.Text ist das eine '1' in edit2.Text erscheint !

danke für alle antworten !

ps:ich prog erst ein paar wochen :wink:

Moderiert von user profile iconraziel: Delphi- und Quote-Tags hinzugefügt.
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: Sa 07.05.05 15:54 
:welcome: im DF!! :D

Also ich werde aus deinem Code leider nicht schlau. ;)

Vor allem das da:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Button1Click(Sender: TObject);
var a: Char; zeilennrarray[1..66of Integer;
begin
a := ['a'];
if Edit1.Text[zeilennrin a then
Edit2.Text := '4'
else
ShowMessage('Fehler!');
end;

verwirrt mich. Edit-Felder haben keine Zeilen auf die du zugreifen kannst. ;) Du hast nur einen langen String, den du ja auch schon gefunden hast: Edit1.Text.

Ich glaube, es wäre am besten, wenn du einfach versuchst, zu erklären, was du machen möchtest. ;)

PS.: Du kannst deinen Code (bzw. solltest) in Delphi-Tags setzten. Einfach oben auf user defined image klicken und abändern. ;)
der_zaehe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 317

WinXP SP2
D6 Pers, D2005 Prof, VS2005
BeitragVerfasst: Sa 07.05.05 16:04 
user profile iconrubooo hat folgendes geschrieben:

 a := ['a']


das ist schon mal sehr seltsam. wundert mich, das das geht. schöner ist.
ausblenden Delphi-Quelltext
1:
a := 'a';					


user profile iconrubooo hat folgendes geschrieben:

 if Edit1.Text[zeilennr] in a then


der index in den [] ist immer eine integer, nie ein array, daher die fehlermeldung des compilers. dort wo jetzt das array steht müsste eine integer sein.

mit dem befehl Pos kannst du prüfen, ob ein string in einem anderem enthalten ist. das könnte dir helfen.

/edit: mist, wieder zu langsam gewesen :autsch: :)

oder schreib idr doch einfach selber eine funktion, die auf das vorhanden sein von zeichn in nem string prüft. das leieß sich realisieren, in dem du mit ner schleife den ganzen string durchläufst und auf das zeichen prüfst:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function pruefe : Boolean;
var
  i : Integer;
begin
  for i := 1 to length(stringdo
    if string[i] = zeichen then
      Result := TRUE
    else
      Result := FALSE;
end;

_________________
[inspirationslos]
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 07.05.05 16:50 
Aber aufpassen, nicht "String" als Variable verwenden, da "String" ein reserviertes Wort in Delphi ist!

ausblenden Delphi-Quelltext
1:
2:
var
  MyString: String;

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
rubooo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52

WIN XP
Delphi 2005 Prof
BeitragVerfasst: So 08.05.05 02:26 
ich glaube ich beschreibe lieber was ich coden will :lol: !

also ! es soll überprüft werden: wenn in der ersten edit-Komponente (edit1.Text) sich ein a (der buchstabe) befindet, soll eine 1 (die zahl) in der zweiten edit-Komponente (edit2.Text) angezeigt werden. Un dieser Vorgang bei dem Klick auf den button !
Kann ich den code auch direkt ins Form einbinden ! so das sich es sofort beim eingeben ändert???

hoffe ich habe es gut und verständlich formuliert !

danke
Blackheart
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

ME
D3Prof.-D6Standard
BeitragVerfasst: So 08.05.05 03:02 
Entweder
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Button1Click(Sender: TObject);
begin
  if Edit1.Text = 'a' then Edit2.Text:='1';
end;

Oder
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if Edit1.Text = 'a' then Edit2.Text:='1';
end;
rubooo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52

WIN XP
Delphi 2005 Prof
BeitragVerfasst: So 08.05.05 03:23 
ja aber wenn ich mehrere a's in der zeile habe dann zeigt er mir sie nicht alle als 1 an ! deswegen wollte ich ja das array machen weil die zeile 66 zeichen lang is ! un überall wo ein a ist soll ein 1 stehen ! :?: :!:
Blackheart
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

ME
D3Prof.-D6Standard
BeitragVerfasst: So 08.05.05 09:17 
Dann machs mal so
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Text:=StringReplace(Memo1.Text,'a','1',[rfReplaceAll]);
end;
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 08.05.05 14:30 
ausblenden Delphi-Quelltext
1:
2:
if Pos('a', Edit1.Text) <> 0 then
  Edit2.Text := 1;


Das will er!

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Blackheart
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

ME
D3Prof.-D6Standard
BeitragVerfasst: So 08.05.05 14:54 
und überall wo ein a ist soll ein 1 stehen !
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit2.Text:=StringReplace(Edit1.Text,'a','1',[rfReplaceAll]);
end;
rubooo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52

WIN XP
Delphi 2005 Prof
BeitragVerfasst: So 08.05.05 14:57 
ne geht alles auch net :cry: !

überall wo in edit1 ein a steht soll nach dem click auf button1 in edit2 eine 1 stehen!
aber es sollen auch noch nachher mehrere buchstaben eingesetzt werden !z.B: b = 2 usw ...

hier ist noch meine icq-uin :: 311432073
Blackheart
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

ME
D3Prof.-D6Standard
BeitragVerfasst: So 08.05.05 15:03 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.Button1Click(Sender: TObject);
var TmpStr: string;
begin
TmpStr:= Edit1.Text;
TmpStr := StringReplace(TmpStr, 'a''1', [rfReplaceAll, rfIgnoreCase]);
TmpStr := StringReplace(TmpStr, 'b''2', [rfReplaceAll, rfIgnoreCase]);
TmpStr := StringReplace(TmpStr, 'c''3', [rfReplaceAll, rfIgnoreCase]);
TmpStr := StringReplace(TmpStr, 'd''4', [rfReplaceAll, rfIgnoreCase]);
Edit2.Text:=(TmpStr);
end;
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: So 08.05.05 16:05 
Einen hab ich noch!
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
Const
  ccSourceChars = 'abcdef';
  ccDestChars   = '123456';
Var
  i,j : Integer;
  s : String;

Begin
  s := edit1.Text;
  For i := 1 to length (s) do begin
    j := Pos (Copy (s,i,1), ccSourceChars);
    if j>0 then 
      s[i] := ccDestChars[j];
    end;
  edit2.Text := s;
End;
rubooo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52

WIN XP
Delphi 2005 Prof
BeitragVerfasst: So 08.05.05 17:36 
danke @Blackheart deine methode war für mich noch am leichtesten zu verstehen ! an alle anderen danke für eure vielen antworten!