Autor Beitrag
daywalker0086
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 243


Delphi 2005 Architect
BeitragVerfasst: Sa 13.12.08 17:57 
Hallo Leute, ich hab folgendes Problem.
Ich hab folgende Funktion, die mir aus einen Hexstring die (Ascii) Buchstaben ausgibt, also den Hexwert in Buchstaben umwandelt.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
 
function Namefiltern(Datengefiltert: array of string): String;
const
Buchstaben = '[a-zA-Z\.\s]';
var
r : TRegExpr;
i: integer;
begin
      r := TRegExpr.Create;
      r.Expression := Buchstaben;
    for D:= 8 to high(Daten) do
      begin
      if  r.Exec (hextostr(Daten[D])) then
      Result:=Result+r.Match[0];
    end;
end;


Aber ich habe mitbekommen das die Hexwerte nach Codepage 850 codiert sind, jetzt passt es nämlich nicht mit den Umlauten und mit dem ß .
Aber wenn ichs händisch mit Codepage 850 übersetze passt es.

Jetzt meine frage wie ich dem programm mitteilen kann, dass es nach Codepage 850 übersetzen soll?
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Sa 13.12.08 22:08 
Ich verstehe überhaupt nicht, was Du willst bzw. was die Funktion macht. Doch, halt! Die Funktion verstehe ich. Die macht... nix, denn Du hast einen Parameter 'Datengefiltert' und greifst auf 'Daten' zu... Weiterhin gibst Du 'r' nicht wieder frei. Zeig doch mal anhand einen Beispiels, was die Funktion machen soll.

Weiterhin könnte 'StrToInt' dein Freund sein (Du musst dem Hex-String ein '$' voranstellen).

_________________
Na denn, dann. Bis dann, denn.
daywalker0086 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 243


Delphi 2005 Architect
BeitragVerfasst: So 14.12.08 12:44 
Ja ich weis hab de Parameter nicht verwendet aber is erstmal egal für das funktionieren.
Also in dem Array Daten steht in jedem Feld ein Hexwert.
Die funktion geht jedes Feld durch(von feld 9 ich weis) und wandelt den Hexwert in nen Asciizeichen um wenn es ein Buchstabe ist und speichert die Buchstaben in Result ab.
Das funktioniert auch einwandfrei.
Es geht darum das aber die Hexwerte nicht ascii codiert sondern Codepage 850 codiert sind.
E1 hex ist nunmal in ascii kein ß aber in codepage 850 .
Da er nach ascii übersetzt sagt er eben E1 ist kein Buchstabe und lässt es weg, dass ist mein Problem.
Genauso verhält es sich mit den Umlauten.
Das wollt ich ihm mitteilen das er nach Codepage 850 übersetzen soll.

Ich hoffe ich konnte es verständlich darstellen.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19341
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 14.12.08 13:15 
Dafür gibt es OemToCharBuff ;-).

forum.delphi-treff.d...wthread.php?t=2149#2
daywalker0086 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 243


Delphi 2005 Architect
BeitragVerfasst: So 14.12.08 13:29 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
function OemToUnicode(const S: WideString): WideString;
begin
  SetLength(Result, Length(S));
  if Length(Result) > 0 then
    OemToCharBuffW(PWideChar(S), PWideChar(Result), Length(Result));
end;

Und wo sag ich ihm da das er nach 850 übersetzen soll? gibt ja auch 437 und so weiter
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19341
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 14.12.08 13:35 
Ich nehme einmal an, dass die Codepage des Systems benutzt wird. Und das ist in Westeuropa 850.

Wenn du die direkt angeben willst, dann könnte dir das helfen:
msdn.microsoft.com/e...ms776413(VS.85).aspx
www.swissdelphicente...showcode.php?id=1692
social.msdn.microsof...7-9fcd-f501e4465222/
daywalker0086 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 243


Delphi 2005 Architect
BeitragVerfasst: Di 16.12.08 16:04 
Wie kann ich denn OemToCharBuff in meone Funktion, die mir von hex nach String umwandelt einbauén?
Da kommen dann immer Fehlermeldungen von Wegen PChar und Widechar
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
 
Function HexToStr(s: String): String;
Var i: Integer;
Begin
  Result:=''; i:=1;
  While i<Length(s) Do Begin
    Result:=Result+Chr(StrToIntDef('$'+Copy(s,i,2),0));
    Inc(i,2);
  End;
End;
daywalker0086 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 243


Delphi 2005 Architect
BeitragVerfasst: Do 18.12.08 22:53 
Kann mir da nochmal jemand helfen?
Habs immernoch nicht hin bekommen das in meine Funktion einzubauen, oder mauss ich da unbedingt ne extra funktion schrieben?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10184
Erhaltene Danke: 1259

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 19.12.08 00:02 
Moin!

Schau mal hier in die FAQ, da wird das auch eingesetzt. :idea: :les: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
daywalker0086 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 243


Delphi 2005 Architect
BeitragVerfasst: Fr 19.12.08 00:37 
also ich habs jetzt so :
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
function Namefiltern(Datengefiltert: array of string): String;
const
Buchstaben = '[a-zA-Z]';
var
r : TRegExpr;
i: integer;
ergebnis: string;
begin
      r := TRegExpr.Create;
      r.Expression := Buchstaben;
    for D:= 8 to high(Daten) do
      begin
      if  r.Exec (hextostr(Daten[D])) then
      ergebnis:=ergebnis+r.Match[0];
    end;
    Result:= OemToCharBuffA(PChar(ergebnis),PChar(ergebnis),Length(ergebnis));
end;


Aber da kommt jetzt incompatible Typen: string und longbool :cry:
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19341
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 19.12.08 02:10 
Schau dir mal die Parameter an... Der Rückgabewert ist ob die Umwandlung erfolgreich war, wo das Ergebnis rein soll musst du als 2. Parameter übergeben.
msdn.microsoft.com/e...ms647494(VS.85).aspx
daywalker0086 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 243


Delphi 2005 Architect
BeitragVerfasst: Sa 20.12.08 19:32 
also ich hab mal geschaut dann müsste es eigentlich so heißen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
Function HexToStr(s: String): String;
Var i: Integer;
ansi: string;
Begin
  Result:=''; i:=1;
  While i<Length(s) Do Begin
    ansi:=ansi+Chr(StrToIntDef('$'+Copy(s,i,2),0));
    Inc(i,2);
  End;
    OemToCharBuffA(PChar(ansi),PChar(Result),Length(ansi));



End;


Kommt aber eine exception beim ausführen und er zeigt die Zeile mit dem OemToCharBuff an
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19341
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 20.12.08 19:33 
Du musst die Länge vorher setzen, denn die Funktion geht davon aus, dass der als dritter Parameter angegebene Speicherplatz an der übergebenen Speicherstelle auch vorhanden ist. Also musst du vorher SetLength benutzen.
daywalker0086 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 243


Delphi 2005 Architect
BeitragVerfasst: Sa 20.12.08 20:02 
Aaaallles klar, es funktioniert endlich, ich danke euch mal wieder...