![]() |
Delphi-Version: 5
Problem mit Pointer in Strukturen
Hallo zusammen,
ich habe ein Problem mit einem Pointer in einer Struktur. Da ich nicht so ganz fit bin mit Pointern, hoffe ich auf Eure Hilfe. Muß Funktionen aus einer C.dll ausführen. Hier der Code:
Delphi-Quellcode:
Danke schon mal für Eure Hilfe!
{* @brief Holds the name of a module}
MODULE_NAME = RECORD name : ARRAY[0..M_MODNAMELEN_A] OF CHAR; // Name of the module. END; {* @brief Structure for a list of module names.} MODULE_LIST = RECORD countModules : UINT16; // Count of module names. names : ^MODULE_NAME; // Array of module names. END; PMODULE_LIST = ^MODULE_LIST; FUNCTION TARGET_GetModules ( targetHandle : M1C_H_TARGET; moduleCount : UINT16; moduleList : PMODULE_LIST ) : SINT32; cdecl; external 'm1com.dll'; ################################# Hier die Verwendung: VAR countModules : UINT16; RetCode : SINT32; i : UINT16; modList : MODULE_LIST; names : ARRAY[0..MaxSwModules] OF MODULE_NAME; BEGIN // Set the ModuleList modList.names := @names; //asking the count of modules on the controller RetCode := TARGET_GetCountModules ( targetHandle, @countModules ); IF ( RetCode = M1C_OK ) THEN RetCode := TARGET_GetModules ( targetHandle, countModules, @modList ); IF ( RetCode = M1C_OK ) THEN BEGIN // clear the list FOR i := 0 TO MaxSwModules DO SWModList[i] := ''; // filling the List FOR i := 0 TO ( countModules - 1 ) DO SWModList[i] := modList.names[i].name; <- hier mosert er beim compilieren. ....... Gruß Rainer |
AW: Problem mit Pointer in Strukturen
Delphi-Quellcode:
warum eigentlich
modList.names.name[i]
names : ^MODULE_NAME; statt names : MODULE_NAME; |
AW: Problem mit Pointer in Strukturen
Zitat:
|
AW: Problem mit Pointer in Strukturen
Hallo,
habe das jetzt so abgeändert.
Delphi-Quellcode:
names : ARRAY[0..MaxSwModules] OF ^MODULE_NAME;
Hier bekomme ich aber immer die Meldung Array-Typ erforderlich
Delphi-Quellcode:
SWModList[i] := modList.names[i].name;
Muß auch mit StrCopy arbeiten, da das eine ein C-String ist und das andere ein Pascal String.
Delphi-Quellcode:
Dies mag der Compiler aber auch nicht.
StrCopy ( @SWModList[i], modList.names[i].name );
Danke für Eure Hilfe Rainer |
AW: Problem mit Pointer in Strukturen
Hallo,
wobei hier weise ich ja die Adresse des Array's zu.
Delphi-Quellcode:
modList.names := @names;
Danke und Gruß Rainer |
AW: Problem mit Pointer in Strukturen
Du hast modList als Record mit einem Zeiger(names) auf den Record MODULE_NAME gelegt, erst dieser Record enthält überhaupt ein Array....
|
AW: Problem mit Pointer in Strukturen
Hallo,
Also das hier ist falsch:
Delphi-Quellcode:
names : ARRAY[0..MaxSwModules] OF ^MODULE_NAME;
Das muss
Delphi-Quellcode:
names : ARRAY[0..MaxSwModules] OF MODULE_NAME;
heißen.
Delphi-Quellcode:
modList.names := @names;
könnte richtig sein. Ich schreibe es aber lieber so:
Delphi-Quellcode:
modList.names := @names[0];
Was ich bei sowas auch empfehlen würde wäre packed record statt record zu benutzen. Ansonsten kann ich aus deinem Post irgendwie nicht so richtig rauslesen wo genau das Problem ist :? @bumi: Zitat:
|
AW: Problem mit Pointer in Strukturen
Hallo Michael,
also das Problem ist, wie komme ich an die Daten die in der modList stecken, dran?
Delphi-Quellcode:
Wenn ich so darauf zugreifen will, bekomme ich immer die Meldung daß ein ARRAY-Typ erforderlich ist.
FOR i := 0 TO ( countModules - 1 ) DO
SWModList[i] := modList.names[i].name; Wenn ich das [i] weglasse kann ich das Programm kompilieren, es wird dann aber immer der selbe Modulname zurückgegeben. Hier die Deklaration von SwModuleList.
Delphi-Quellcode:
Danke für Eure Hilfe !!!
SwModuleList = ARRAY[0..MaxSwModules] OF STRING[12];
|
AW: Problem mit Pointer in Strukturen
Hallo,
Du kommst (z.B.) so an die Daten:
Delphi-Quellcode:
FOR i := 0 to (countModules - 1) do
begin SWModList[i] := modList.names^.name; inc(modList.names); end; |
AW: Problem mit Pointer in Strukturen
Hallo Michael,
danke für Deine Hilfe. Diese Problem konnte ich jetzt lösen. Schöne Grüße aus Österreich Rainer |
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:52 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz