Autor Beitrag
xan553
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 67



BeitragVerfasst: So 28.01.07 15:04 
hy,

ich bräuchte hilfe bei einem code,
der mir auf dem feld edit1 immer 6 stellen nimmt und sie dann umwandelt
und dann die nächsten 6 stellen usw.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 28.01.07 15:07 
user profile iconxan553 hat folgendes geschrieben:
hy,

ich bräuchte hilfe bei einem code,
der mir auf dem feld edit1 immer 6 stellen nimmt und sie dann umwandelt
und dann die nächsten 6 stellen usw.

Inwiefern 'umwandeln'?
Schau dir mal Copy an. ;)

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
xan553 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 67



BeitragVerfasst: So 28.01.07 15:15 
also entschuldigung für die ungenaue frage hier etwas umfangreicher.

ich benutze diesen quelltext zum umwandeln meiner buchstaben:

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', '000101', [rfReplaceAll, rfIgnoreCase]);
  TmpStr := StringReplace(TmpStr, 'B', '001101', [rfReplaceAll, rfIgnoreCase]);
  TmpStr := StringReplace(TmpStr, 'C', '010110', [rfReplaceAll, rfIgnoreCase]);
Edit2.Text:=TmpStr;
end;


so dann gebe ich ein ABC und es kommt wie gewünscht 000101001101010110 heraus.

wenn ich es wieder in buchstaben umwandeln will, habe ich diesen quellcode:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.Button2Click(Sender: TObject);
var
TmpStr: string;
begin
  TmpStr:= Edit1.Text;
  TmpStr := StringReplace(TmpStr, '000101', 'a', [rfReplaceAll, rfIgnoreCase]);
  TmpStr := StringReplace(TmpStr, '001101', 'b', [rfReplaceAll, rfIgnoreCase]);
  TmpStr := StringReplace(TmpStr, '010110', 'c', [rfReplaceAll, rfIgnoreCase]);
Edit2.text:=TmpStr;
end;


das funktioniert auch noch

aber wenn ich zum beispiel eingebe:

Dieses forum ist klasse

dann bekomme ich :

001010000010010001001000010001001000011100000011010101010000011000000
100011100000010001000001100011100001111011010000101001000001000010001

stimmt soweit auch.

aber wenn ich es wieder in buchstaben umwandeln will bekomme ich:

diese001f10000bo0f00000e1,e0fzf11la0010i00e

und ich denke das ich dieses problem nur dann in den griff bekomme, wenn ich immer nur 6 stellen auf einmal bearbeiten lasse.

Moderiert von user profile iconGausi: Zeilenumbruch in der langen 0-1-Kette eingefügt.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 28.01.07 15:18 
Ja dann nimmst du dir mit Copy in einer Schleife eben immer nur 6 Buchstaben. ;)

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Grenzgaenger
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 28.01.07 15:58 
dein code kann nicht funktionieren, da die 0 und 1 nicht eindeutig sind, und du mit dem replace irgend was ab irgendeiner stelle rausgreiffst und etwas ersetzt. du musst hier, zeichen für zeichen umwandeln...

z.b.
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
while length(tempstr1) > 0 do
begin
 tempstr2 := copy(tempstr1,1,6);
 delete(tempstr1,1,6);
 case tempstr2 do
   '00101010': tempstr3 := tempstr3 + 'xxx';
   '01010101': tempstr3 := tempstr3 + 'yyy';
   ....
 endcase
enddo;
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: So 28.01.07 16:03 
case mit mehreren zeichen geht nicht, das geht nur per Schleife, jeweils 6 Buchstaben kopieren und mit if ersetzen.
Alternative: Eine Konstante mit den ganzen Ersetzungen und dann per Schleife durch statt mit if..else!
xan553 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 67



BeitragVerfasst: So 28.01.07 18:06 
was wäre leichter unter der bedinung das ich noch ziehmlicher neuling mit delphi bin?
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: So 28.01.07 18:37 
Die Konstante ist definitiv einfacher!
Vorausgesetzt man weiß, wie man die deklariert... ;-)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
const
  Chars: array[0..2] of String = ('A', 'B', 'C');
  CharReplaces: array[0..2] of String  = ('000011', '110110', '010111');
var
  i: Integer;
begin
  for i := 0 to High(CharReplaces) do
  // Alle Ersetzungen durchgehen...
  begin
    if Pos(CharReplaces[i], YourString) = 1 then
      // ...und nachsehen ob YourString damit anfängt
      Ergebnis := Ergebnis + Chars[i];
    Delete(YourString, 1, Length(CharReplaces[i]));
  end;

So, YourString ist das wo die ersetzten Sachen drin sind, also 1010101010101010..., und Ergebnis ist das wo es reinsoll...
Das ganze musst du jetzt noch machen, bis der String YourString leer ist, weil alles rausgelöscht wurde.
xan553 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 67



BeitragVerfasst: So 28.01.07 18:53 
so müsste es doch stimmen oder?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.Button1Click(Sender: TObject);
const
  Chars: array[0..2] of String = ('A', 'B', 'C');
  CharReplaces: array[0..2] of String  = ('000011', '110110', '010111');
var
  i: Integer;
begin
  for i := 0 to High(CharReplaces) do
  // Alle Ersetzungen durchgehen...
  begin
    if Pos(CharReplaces[i], edit1.text) = 1 then
      // ...und nachsehen ob YourString damit anfängt
      edit2.text := edit2.text + Chars[i];
    Delete(edit1.text, 1, Length(CharReplaces[i]));
  end;
end;
end.
xan553 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 67



BeitragVerfasst: So 28.01.07 19:52 
dies funktioniert leider nicht, ich bekomme folgende fehlermeldung:

[Error] Unit1.pas(42): Constant object cannot be passed as var parameter
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: So 28.01.07 20:35 
Du musst an Delete eine String-Variable übergeben...
Der Grund: Delete muss ja den String ändern. Und Edit1.Text ist eine Eigenschaft und keine Variable. Deshalb kann die nicht direkt wie eine String-Variable verändert werden. Die kann zwar gesetzt werden, aber eben als Eigenschaft und nicht als Variable. Davon merkt man aber sonst nix, weil man in beiden Fällen := benutzt ;-).
Deshalb: Erst den Edit-Inhalt in eine String-Variable und dann damit weitermachen...
xan553 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 67



BeitragVerfasst: So 28.01.07 20:52 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
const
  Chars: array[0..2] of String = ('A', 'B', 'C');
  CharReplaces: array[0..2] of String  = ('000011', '110110', '010111');
var
  i: Integer;
  s: String;
begin
  s:= edit1.text;
   for i := 0 to High(CharReplaces) do
  // Alle Ersetzungen durchgehen...
  begin
    if Pos(CharReplaces[i], edit1.text) = 1 then
      // ...und nachsehen ob YourString damit anfängt
      edit2.text := edit2.text + Chars[i];
   s:= Delete(edit1.text, 1, Length(CharReplaces[i]));
   edit2.text := s;
  end;
end;
end.


so müsste es aber dann glaub ich stimmen, aber die fehlermeldung kommt immernoch.
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: So 28.01.07 21:00 
Ähh, sagen wir mal: fast... ;-)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
const
  Chars: array[0..2] of String = ('A', 'B', 'C');
  CharReplaces: array[0..2] of String  = ('000011', '110110', '010111');
var
  i: Integer;
  s: String;
begin
  edit2.Text := '';
  s:= edit1.text;
// hier noch das while hin
  for i := 0 to High(CharReplaces) do
  // Alle Ersetzungen durchgehen...
  begin
    if Pos(CharReplaces[i], s) = 1 then
      // ...und nachsehen ob s damit anfängt
      edit2.text := edit2.text + Chars[i];
    Delete(s, 1, Length(CharReplaces[i]));
  end;
end;

end.

Dann fehlt da aber noch die while-Schleife drumherum...
Denn du löschst ja stückchenweise jeweils die gefundene Ersetzung, danach musst du aber weitermachen solange noch was zum Ersetzen da ist, spürich der String nicht leer ist.
Tipp: Diese Schleife siehst du bei user profile iconGrenzgaengers Post...
xan553 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 67



BeitragVerfasst: So 28.01.07 21:15 
danke soweit, habs mal kurz ausprobiert, das prog hat sich leider aufgehängt, ich werde es morgen nochmal anschauen bin zu müde :wink:
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: So 28.01.07 21:26 
Hallo,

um mal auf user profile iconGrenzgaengers Vorschlag zurückzukommen.
Es wäre in diesem speziellen Fall auch folgendes möglich:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
//...
case StrToInt(tempstr2) do  
  101010  : tempstr3 := tempstr3 + 'xxx';  
  1010101 : tempstr3 := tempstr3 + 'yyy';  
  //...  
 end;
//...

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
xan553 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 67



BeitragVerfasst: Mo 29.01.07 12:26 
also das mit den konstanten will nicht klappen, da hängt sich das programm auf
xan553 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 67



BeitragVerfasst: Mo 29.01.07 16:55 
Hat keiner ne idee an was es liegen könnte?
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Mo 29.01.07 18:31 
user profile iconxan553 hat folgendes geschrieben:
Hat keiner ne idee an was es liegen könnte?

Ich hätte schon eine, Du wechselst von Code zu Code ohne richtig zu begreifen was Du da Eigentlich tust.
Vieleicht solltest Du dir doch erst einige Anfänger Tutorials antun ! ("antun" - gibt es so ein Wort ?)
xan553 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 67



BeitragVerfasst: Mo 29.01.07 18:36 
jop son wort gibt es. schreibt sich aber glaub antuen ^^
Grenzgaenger
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 29.01.07 23:52 
anbei mal 'ne kleine decode funktion. hoffe sie hilft.

ausserdem scheinst du noch im encode einen bug zu haben, so dass diese nicht sauber funktioniert. diese solltest auch mal überarbeiten.

ausblenden volle Höhe 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:
26:
27:
28:
29:
30:
31:
function decode(s: string): string;
type
 string6=string[6];
 string7=string[7]; //alternativ
const
 arr: array[0..2] of string6 = ('000101', '001101', '010110');
 arr1: array[0..2] of string7 = ('000101A', '001101B', '010110C');   //alternativ
var
 s2: string;
 i: integer;
begin
 result := '';
 if (length(s) mod 6) = 0 then
 begin
  while length(s) > 0 do
  begin
   s2 := copy(s,1,6);
   delete(s,1,6);
   for i := 0 to high(arr) do
   begin
//    if s2 = arr[i] then result := result + char(i + ord('A')); // //entfernen, wenn nicht alternative zu wählen ist.
    if s2 = copy(arr1[i],1,6) then result := result + arr1[i,7]; //alternativ, auskommentieren, wenn nicht alternative zu wählen ist.
   end;
  end;
 end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 edit2.text := decode(edit1.text);
end;