Autor Beitrag
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mi 08.09.10 17:37 
Hallo liebes Forum.

Ich habe folgenden Code aus einem API Beispiel eines Visitenkartenscanners:
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:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
function CheckStatus(errorcode: integer; functionName: string): boolean;
var
  errormessage: String;
  remedy: String;
  composedMsg: String;
  szmessage, szremedy: integer;
  retval: integer;
begin
  szmessage := 256;
  szremedy := 256;
  errormessage := StringOfChar(' ', szmessage);
  remedy := StringOfChar(' ', szremedy);
  if (errorcode = CRTK_ERR_CANCELED)
    or (errorcode = CRTK_NO_TEXT)
    or (errorcode = CRTK_ERR_NO_IMAGE)
    then begin
    Result := False;
    exit;
  end;
  if (errorcode <> CRTK_SUCCESS) then begin

        //   Translate error code into message and remedy. if the
        //   translation fails, print a generic message. Otherwise,
        //   explain the problem.

    retval := CRTK_GetErrorMessage(errorcode, PChar(errormessage), szMessage, PChar(remedy), szRemedy);
    SetLength(errormessage, StrLen(PChar(errormessage)));
    SetLength(remedy, StrLen(PChar(remedy)));
    if (retval <> CRTK_SUCCESS) then
      composedMsg := functionName + ' failed because of an unexpected error: '
        + IntToStr(errorcode)
    else
      composedMsg := functionName + ' failed because '
        + errormessage + '. '
        + remedy;
    {end if}
    MessageDlg(composedMsg, mtError, [mbOK], 0);
    Result := False;
  end
  else Result := True;
end;


Dieses Beispiel ist gefühlte 100 Jahre alt und funktionierte in der mit Delphi 6 kompilierten Demo auch super.
Wenn ich das jetzt mit meinem Delphi 2009 starte kommt da nur Kauderwelsch raus.
Wenn ich dann allerdings wiederum in der Variablendeklaration die 3 Strings auf AnsiStringumstelle klappts wieder. Daher vermute ich mal, da haut was mit der Unicode-Umwandlung nicht hin.

Jetzt bin ich aber leider nicht so versiert, was dieses ganze Unicodezeug betrifft.
Wie müsste ich den Code denn ändern, dass mir Delphi das auch mit Unicode Strings macht?

Danke!
Matze

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 480

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 08.09.10 17:47 
Gibt es denn eine Version von CRTK_GetErrorMessage, die einen UTF16-Unicode-String zurückliefert, bzw. in die Parameter errormessage bzw. remedy reinschreibt? Denn nur dann würde das ja Sinn ergeben. Wenn die API nur Ansi zurückliefert, wird man da sonst nichts machen können. :nixweiss:
Und wenn es klappt, dann ist es doch gut so, oder nicht? ;-)

Btw.: Bei sowas nicht nur String durch AnsiString ersetzen, sondern auch die PChar durch PAnsiChar.

_________________
We are, we were and will not be.
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mi 08.09.10 18:51 
Oh ja stimmt.
Das ist ja Unfug mit dem Unicode. Die Funktion gibt ja kein Unicode zurück... Doof von mir.

Aber danke für den Tipp mit dem PAnsiChar. Das funktioniert jetzt wunderbar!

_________________
In the beginning was the word.
And the word was content-type: text/plain.