Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Problem: Format %p ungültig o. nicht kompatibel mit Argument (https://www.delphipraxis.net/51852-problem-format-p-ungueltig-o-nicht-kompatibel-mit-argument.html)

carknue 20. Aug 2005 14:27


Problem: Format %p ungültig o. nicht kompatibel mit Argument
 
Ich programmiere ein kleines Freeware Tool, welches die Ansteuerung von verschiedenen Radios übernimmt. Nun bin ich bei einem neuen Empfänger, der per dll angesteuert wird auf ein merkwürdiges Problem gestoßen, welches ich mir nicht erkären kann. Mein Problem ist, dass ich bei einem Aufruf einer Funktion aus dieser externen dll eine EConvertError '%P' Exception bekomme. Die Exception bekomme ich nur, wenn ich das Programm über die IDE(Delphi 6) laufenlasse. Starte ich direkt die exe, gibt es ohne error Behandlung im Programm nur die Meldung "Format %p ungültig o. nicht kompatibel mit Argument" Diese läßt sich mit OK wegklicken und es läuft einwandfrei weiter, auch die Funktion wurde korrekt ausgeführt. Aber dies passiert nur, wenn ich diese Funktion aus bestimmten Proceduren meines Programms aufrufe. Hier zu erstmal die C++ Header Datei mit dem Funktionaufruf für die dll. Es geht um die Funktion FrontendSetMode aus der dll. Der Aufruf innerhalb meiner "procedure TForm1.checkaorClick(Sender: TObject)" funktioniert ohne Probleme, rufe ich sie allerdings mit den gleichen Parametern über meine "Procedure Tform1.SetDWTMode(mode: smallint)" auf, so kommt der Format Fehlermeldung. Jetzt kommt dass, was ich überhaupt nicht verstehe, denn wenn ich die Funktion in meiner "procedure Tform1.SetFreq(freq: string)" aufrufe, kommt keine Fehlermeldung. Und wenn ich, wie in "procedure TForm1.Button4Click(Sender: TObject)" die Exception abfangen will, wird das Programm ander Stelle ohne Meldung geschlossen. Wer weiß Rat?


Zitat:

/*! Frontend error codes, all values not listed are RFU */
typedef enum _tFrontendError
{
eFrontendOk = 0, /*!< no error */
eFrontendErrorNotInitialized = -1, /*!< DLL not initialized (call FrontendOpen() first */
eFrontendErrorReceiverDisconnected = -2, /*!< receiver is not connected to the PC */
eFrontendErrorInvalidParameter = -3, /*!< parameter for the command was invalid */
eFrontendErrorCommandFailure = -4, /*!< command was not executed */
} tFrontendError;



/*! Frontend modes, all values not listed are RFU */
typedef enum _tFrontendMode
{
eFrontendModeUndefined = 0, /*!< undefined/unknown mode */
eFrontendModeDrm = 1, /*!< mode for DRM demodulation */
eFrontendModeAm = 2, /*!< mode for AM demodulation */
eFrontendModeFm = 6, /*!< mode for FM demodulation */
} tFrontendMode

/* ################################################## ################################################ */


/*! open Frontend, called once on startup; to recover from an error FrontendClose
* followed by a further FrontendOpen will be called
*
* \return <0 error, see _tFrontendError, >0 API Version see cFrontendApiVersion
*/
FRONTEND_API
short
FRONTEND_API_CALL
FrontendOpen(void);



/*! close Frontend, called on shutdown of the receiver or while recovering from errors
*
* \return 0 = no error, <0 error see _tFrontendError
*/
FRONTEND_API
short
FRONTEND_API_CALL
FrontendClose(void);

/*! set frontend mode
* \param mode set frontend to the given mode
* \return 0 = no error, <0 error, see _tFrontendError
*/
FRONTEND_API
short
FRONTEND_API_CALL
FrontendSetMode(tFrontendMode mode);


/*! set frontend to the given frequency in Hz
* \param freq frequency in Hz
* the allowed intervals are 150000 .. 29999000 for DRM/AM, and 87500000 .. 108000000 for FM
* \return 0 = no error, <0 error, see _tFrontendError
*/
FRONTEND_API
short
FRONTEND_API_CALL
FrontendSetFrequency(double freq);
Hier der relevante Code meines Programms

Delphi-Quellcode:
interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, sndkey32, StdCtrls, ComCtrls, ExtCtrls, inifiles, DateUtils,
  CPort, CPortCtl, Grids, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdHTTP, Menus;

type
  TForm1 = class(TForm)
   
    Procedure SetDWTMode(mode: smallint);
    procedure SetFreq(freq: string);
    procedure dwtmodClick(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure checkaorClick(Sender: TObject);
   
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
 
  dwt: smallint;

  FrontendOpen: function(): Integer; stdcall;
  FrontendClose: function(): Integer; stdcall;
  FrontendSetFrequency: function(freq: double): smallint; stdcall;
  FrontendSetMode: function(mode: smallint): smallint; stdcall;
  FrontendSetAntennaMode: function(n: smallint): smallint; stdcall;

implementation

{$R *.dfm}

Procedure Tform1.SetDWTMode(mode: smallint);
begin
if mode=1 then FrontendSetMode(1);
if mode=2 then FrontendSetMode(2);
if mode=6 then FrontendSetMode(6);
end;

procedure Tform1.SetFreq(freq: string);
var rfreq: integer;
    dwtfreq:double;

begin

 rfreq:=strtoint(freq);
 if (rfreq > 150) and (rfreq < 29999) then
 begin
 edit1.Text:=freq;
 if cbrx.ItemIndex=10 then
 begin
 dwtfreq:=rfreq*1000;
 dwt:=FrontendSetFrequency(dwtfreq);
 label2.Caption:=inttostr(dwt);
 end
end
end;

procedure TForm1.checkaorClick(Sender: TObject);

 begin
   ShowMessage('Be sure that the DWT application is not running anymore!');
   Dll:=LoadLibrary('afgusbfe.dll');
   dwt:=69;

   if (Dll=0) then ShowMessage('afgusbfe.dll not found !')
   else begin
    FrontendOpen:=GetProcAddress(dll,'FrontendOpen');
    FrontendClose:=GetProcAddress(dll,'FrontendClose');
    FrontendSetFrequency:=GetProcAddress(dll,'FrontendSetFrequency');
    FrontendSetMode:=GetProcAddress(dll,'FrontendSetMode');
    FrontendSetAntennaMode:=GetProcAddress(dll,'FrontendSetAntennaMode');

     dwt:=FrontendOpen;
     label2.Caption:=inttostr(dwt);
     dwt:=FrontendSetFrequency(3995000);
     label2.Caption:=inttostr(dwt);
     dwt:=FrontendSetMode(1);
     label2.Caption:=inttostr(dwt);
     ShowMessage('1');
     dwt:=FrontendSetMode(2);
     label2.Caption:=inttostr(dwt);
     ShowMessage('2');
     dwt:=FrontendSetMode(6);
     label2.Caption:=inttostr(dwt);
     ShowMessage('6');
   end;
 end;

procedure TForm1.dwtmodClick(Sender: TObject);
begin
 if dwtmod.ItemIndex=0 then SetDWTMode(1);
 if dwtmod.ItemIndex=1 then SetDWTMode(2);
 if dwtmod.ItemIndex=2 then SetDWTMode(6);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
try
FrontendSetMode(6);
except
on EConvertError do
begin
label2.Caption:='Error';
end;
end;
end;

end.

Luckie 20. Aug 2005 14:57

Re: Problem: Format %p ungültig o. nicht kompatibel mit Argu
 
300 Zeilen sind für dich relevat? :shock: Kürz es entweder oder pack es als Anhang zu deinem Beitrag dazu.

carknue 20. Aug 2005 15:24

Re: Problem: Format %p ungültig o. nicht kompatibel mit Argu
 
done.

turboPASCAL 20. Aug 2005 16:10

Re: Problem: Format %p ungültig o. nicht kompatibel mit Argu
 
EConvertError '%P' weist doch auf einen FormatString Fehler hin, also in Form von:

Code:
[b][...][/b]
  ShowMessage(Format('Pointer = %p', [text] ));
[b][...][/b]
Richtig:
Code:
[b][...][/b]
[b] var[/b]
  text : [b]string[/b];
[b]begin[/b]
  Trxt := 'Hallo';
  ShowMessage(Format('Pointer = %p', [@text]));
  ShowMessage(Format('Pointer = %p', [addr(text)]));
[b]end;[/b]
Zitat:

%P Zeiger: Das Argument muß ein Zeigerwert sein. Der Wert wird in einen String mit acht Zeichen, der den hexadezimalen Wert des Zeigers darstellt, konvertiert.
:gruebel:

carknue 20. Aug 2005 17:13

Re: Problem: Format %p ungültig o. nicht kompatibel mit Argu
 
Ja aber die Funktion FrontendSetMode liefert einen Smallint und das Argument ist auch ein Smallint. Undw ieso klappt der der Aufruf dwt:=FrontendSetMode(2); in den Proceduren checkaorClick(Sender: TObject) und SetFreq(freq: string) aber nicht aus SetDWTMode(mode: smallint)?

:gruebel:

turboPASCAL 20. Aug 2005 18:23

Re: Problem: Format %p ungültig o. nicht kompatibel mit Argu
 
Delphi-Quellcode:
Procedure SetDWTMode(mode: smallint);
Ist wo, und sieht wie aus ?

Benutzt Du auch mal die Entertaste ? ;-)


// Edit: Hänge doch bitte mal die C Header-File als Anhang mit dran.

Und ich habe nur nen kleinen Bildschirm mit max. 80 Zeichen :wink:

/* ################################################## ###################### */

carknue 20. Aug 2005 18:43

Re: Problem: Format %p ungültig o. nicht kompatibel mit Argu
 
Liste der Anhänge anzeigen (Anzahl: 1)
Ok, hier ist das c header file.

turboPASCAL 20. Aug 2005 19:02

Re: Problem: Format %p ungültig o. nicht kompatibel mit Argu
 
Was mir Auffällt:

smallint ?

Delphi-Quellcode:
type
  short = shortint;
Aber die Procedure SetDWTMode finde ich nicht in der Header File.

Hast du die C-Header richtig übersetzt ?

carknue 20. Aug 2005 19:28

Re: Problem: Format %p ungültig o. nicht kompatibel mit Argu
 
short von C++ entspricht smallint bei Delphi.
Shortint ist zu klein, obwohl es für die auftretenden Werte
reichen würde.

Es geht um die Funktion FrontendSetMode aus der header Datei.

Delphi-Quellcode:
Procedure Tform1.SetDWTMode(mode: smallint);
begin
if mode=1 then FrontendSetMode(1);
if mode=2 then FrontendSetMode(2);
if mode=6 then FrontendSetMode(6);
end;
Declariert ist es wie folgt:
Delphi-Quellcode:
type
  TForm1 = class(TForm)
   
    Procedure SetDWTMode(mode: smallint);
    procedure SetFreq(freq: string);
    procedure dwtmodClick(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure checkaorClick(Sender: TObject);
   
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
 
  dwt: smallint;

  FrontendOpen: function(): Integer; stdcall;
  FrontendClose: function(): Integer; stdcall;
  FrontendSetFrequency: function(freq: double): smallint; stdcall;
  FrontendSetMode: function(mode: smallint): smallint; stdcall;
  FrontendSetAntennaMode: function(n: smallint): smallint; stdcall;

implementation

{$R *.dfm}
Die dll lade ich dann so:
Delphi-Quellcode:

Dll:=LoadLibrary('afgusbfe.dll');
   dwt:=69;

   if (Dll=0) then ShowMessage('afgusbfe.dll not found !')
   else begin
    FrontendOpen:=GetProcAddress(dll,'FrontendOpen');
    FrontendClose:=GetProcAddress(dll,'FrontendClose');
    FrontendSetFrequency:=GetProcAddress(dll,'FrontendSetFrequency');
    FrontendSetMode:=GetProcAddress(dll,'FrontendSetMode');
    FrontendSetAntennaMode:=GetProcAddress(dll,'FrontendSetAntennaMode');

     dwt:=FrontendOpen;
     dwt:=FrontendSetFrequency(3995000);
     dwt:=FrontendSetMode(1);
Bis hier geht der Aufruf von dwt:=FrontendSetMode(1); einwandfrei.
In dieser Procedure kommt aber die Formatfehlermeldung:
Delphi-Quellcode:
Procedure Tform1.SetDWTMode(mode: smallint);
begin
if mode=1 then dwt:=FrontendSetMode(1);
if mode=2 then dwt:=FrontendSetMode(2);
if mode=6 then dwt:=FrontendSetMode(6);
end;
In dieser Procedure klappt es dagegen wieder:

Delphi-Quellcode:
procedure Tform1.SetFreq(freq: string);
var rfreq: integer;
    dwtfreq:double;

begin

rfreq:=strtoint(freq);
dwtfreq:=rfreq*1000;
dwt:=FrontendSetFrequency(dwtfreq);
label2.Caption:=inttostr(dwt);
dwt:=FrontendSetMode(1);

end;

Phistev 20. Aug 2005 20:23

Re: Problem: Format %p ungültig o. nicht kompatibel mit Argu
 
Short soll smallint (Ganzzahl) sein? :gruebel: In SetFreq übergibst du ein Double (Fließkommazahl), und das scheint zu funktionieren

/Edit: Nachgeguckt, short scheint wirklich smallint zu sein. Wieso funktioniert dann der Double-Wert?


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:38 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz