AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

Union Übersetzung nach Pascal

Ein Thema von Neutral General · begonnen am 12. Mär 2007 · letzter Beitrag vom 30. Mär 2007
Antwort Antwort
Seite 1 von 3  1 23   
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#1

Union Übersetzung nach Pascal

  Alt 12. Mär 2007, 15:04
Hi,

Auf Assabards Seite habe ich folgende Übersetzung gefunden


Code:
union {
    struct {
      DWORD Signature;
      DWORD CheckSum;
    } Mbr;
    struct {
      GUID DiskId;
    } Gpt;
  };


Delphi-Quellcode:
case Integer of
    0: (
       Signature: DWORD;
       CheckSum: DWORD
       );
    1: (
       DiskId: TGUID
       );
Ok das ist nachvollziebar... ABER was ist soll das hier bedeuten:

Code:
union {
        PARTITION_INFORMATION_MBR Mbr;
        PARTITION_INFORMATION_GPT Gpt;
    };
?

Delphi-Quellcode:
Case Integer of
 0: PARTITION_INFORMATION_MBR;
 1: PARTITION_INFORMATION_GPT;
end;
... Aber was für einen Sinn ergibt das?

Gruß
Neutral General
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
Benutzerbild von CK_CK
CK_CK

Registriert seit: 30. Aug 2005
Ort: Dortmund, Germany
388 Beiträge
 
Delphi 2006 Enterprise
 
#2

Re: Union Übersetzung nach Pascal

  Alt 12. Mär 2007, 15:08
Hi!
Es wäre wohl eher:
Delphi-Quellcode:
case Integer of
  0: (Mbr: PARTITION_INFORMATION_MBR);
  1: (Gpt: PARTITION_INFORMATION_GPT);
end;
Viele Grüße,
Chris

Edit: Guck' mal [HIER], wie die's gelöst haben...
Chris
» «
Mehr von mir (Programme, etc.): http://www.kroegerama.de
  Mit Zitat antworten Zitat
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#3

Re: Union Übersetzung nach Pascal

  Alt 12. Mär 2007, 15:19
Zitat von CK_CK:
Edit: Guck' mal [HIER], wie die's gelöst haben...
--------- __________ -----------

Die Schweine. Das wollte ich doch machen

Pf.. Ich machs trotzdem -.-

PS: Danke
PPS: Wobei das Problem auch noch bei ULong64 liegt.. Die benutzen da ein DWORD64. Sowas existiert bei mir aber nicht..
PPPS: Ich seh grad die definieren ULong64 als Int64... Ehm naja ich weiß zwar nicht seit wann Integers unsigned sind aber egal

Gruß
Neutral General
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu
Online

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.114 Beiträge
 
Delphi 12 Athens
 
#4

Re: Union Übersetzung nach Pascal

  Alt 12. Mär 2007, 15:26
Delphi-Quellcode:
// ab Delphi 6:
Type DWord64 = System.UInt64;
   LargeWord = System.UInt64;


// und D1 bis D5:
Type DWord64 = Type System.Int64;
   LargeWord = Type System.Int64;
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#5

Re: Union Übersetzung nach Pascal

  Alt 12. Mär 2007, 15:53
Ok danke aber was heißt das hier:

Delphi-Quellcode:
_PARTITION_INFORMATION_EX = record
  PartitionStyle: PARTITION_STYLE;
  StartingOffset: LARGE_INTEGER;
  PartitionLength: LARGE_INTEGER;
  PartitionNumber: ULONG;
  RewritePartition: Boolean;
  case Integer of
    0: (Mbr: PARTITION_INFORMATION_MBR);
    1: (Gpt: PARTITION_INFORMATION_GPT);
end;
Und wie soll ich die markierte Zeile in diesem Record übersetzen ? o.O

Code:
typedef struct _DRIVE_LAYOUT_INFORMATION_EX {
    ULONG PartitionStyle;
    ULONG PartitionCount;
    union {
        DRIVE_LAYOUT_INFORMATION_MBR Mbr;
        DRIVE_LAYOUT_INFORMATION_GPT Gpt;
    };
    PARTITION_INFORMATION_EX PartitionEntry[1]; //<---- Was soll die [1] ?
}
PS: Man man Michi -.- Erst gucken dann schreiben...

PartitionEntry: array [0..0] of PARTITION_INFORMATION_EX; Gruß
Neutral General
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu
Online

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.114 Beiträge
 
Delphi 12 Athens
 
#6

Re: Union Übersetzung nach Pascal

  Alt 12. Mär 2007, 16:05
Aber vergiß dann nicht vorher abzufragen wieviele Partitionen vorhanden sind, denn du mußt ja mindestens für jede Partition da hinten Speicherplatz reservieren.


Da ich selber ums mir einfacher zu machen und Delphi die Verwaltung des Speicherplatzes aufzubrumen gerne Variablen verwende, hab ich das einfach so gelöst

mit Variable:
Delphi-Quellcode:
Type _DRIVE_LAYOUT_INFORMATION_EX = packed Record
    PartitionStyle: _PARTITION_STYLE;
    PartitionCount: LongWord;
    Union: packed Record Case _PARTITION_STYLE of
      PARTITION_STYLE_MBR: (Mbr: _DRIVE_LAYOUT_INFORMATION_MBR);
      PARTITION_STYLE_GPT: (Gpt: _DRIVE_LAYOUT_INFORMATION_GPT);
    End;
    PartitionEntry: packed Array[0..31] of _PARTITION_INFORMATION_EX;
  End;

Var DLI: _DRIVE_LAYOUT_INFORMATION_EX;

DeviceIoControl(Dh, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, nil, 0,
  @DLI, SizeOf(_DRIVE_LAYOUT_INFORMATION_EX), W, nil);
...
über Pointer:
Delphi-Quellcode:
Type _DRIVE_LAYOUT_INFORMATION_EX = packed Record
    PartitionStyle: _PARTITION_STYLE;
    PartitionCount: LongWord;
    Union: packed Record Case _PARTITION_STYLE of
      PARTITION_STYLE_MBR: (Mbr: _DRIVE_LAYOUT_INFORMATION_MBR);
      PARTITION_STYLE_GPT: (Gpt: _DRIVE_LAYOUT_INFORMATION_GPT);
    End;
    PartitionEntry: packed Array[0..0] of _PARTITION_INFORMATION_EX;
  End;
  pDRIVE_LAYOUT_INFORMATION_EX = _DRIVE_LAYOUT_INFORMATION_EX^;

Var pDLI: pDRIVE_LAYOUT_INFORMATION_EX;

DLI := GetMem(SizeOf(_DRIVE_LAYOUT_INFORMATION_EX)
  + SizeOf(_PARTITION_INFORMATION_EX) * (AnzahlDerPartitionen - 1));
Try
  DeviceIoControl(Dh, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, nil, 0,
    DLI, SizeOf(_DRIVE_LAYOUT_INFORMATION_EX), W, nil);
  ...
Finally
  FreeMem(DLI);
End;

// -1 da Array[0..0] of _PARTITION_INFORMATION_EX bereits einmal _PARTITION_INFORMATION_EX einschließt
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#7

Re: Union Übersetzung nach Pascal

  Alt 12. Mär 2007, 16:16
Ok danke aber woher weiß ich wie viele Partitionen auf der Festplatte drauf sind ? o.O
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu
Online

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.114 Beiträge
 
Delphi 12 Athens
 
#8

Re: Union Übersetzung nach Pascal

  Alt 12. Mär 2007, 16:22
von nirgendwo?

na ja, im Grunde machen es alle einfach so ... sie reservieren mehr, als es vermutlich gibt
und lassen sich dann im Nachhinein überraschen was in PartitionCount steht.

also meist einfach:
Delphi-Quellcode:
DLI := GetMem(SizeOf(_DRIVE_LAYOUT_INFORMATION_EX)
  + SizeOf(_PARTITION_INFORMATION_EX) * 31);
Im Grunde mach ich genau das Selbe ... oder bist du der Meinung, daß jemand mehr als 32 Partitionen auf einer Platte hat? (sehr unwarscheinlich)
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#9

Re: Union Übersetzung nach Pascal

  Alt 12. Mär 2007, 16:36
Also mein Problem liegt im Moment hauptsächlich bei GetMem^^

procedure GetMem(var P: Pointer; Size: Integer); So ist das bei mir definiert. Und
Delphi-Quellcode:
DLI := GetMem(SizeOf(_DRIVE_LAYOUT_INFORMATION_EX)
  + SizeOf(_PARTITION_INFORMATION_EX) * 31);
funktioniert daher auch nicht so toll....

EDIT: Ja ok.. man muss es ander schreiben...

Delphi-Quellcode:
Size := SizeOf(_DRIVE_LAYOUT_INFORMATION_EX) + SizeOf(_PARTITION_INFORMATION_EX)*31;

GetMem(P,Size);
DeviceIoControl(H,IOCTL_DISK_GET_DRIVE_LAYOUT_EX,nil,0,P,Size,OutBytes,nil)
FreeMem(P);
Aber auf jeden Fall herzlichen Dank für die gute Hilfe

Gruß
Neutral General


EDIT: Oh man... Ich bekomme jetzt als P.PartitionCount 32 zurück..... Damit kann ich ja gar nix anfangen und P.ParitionEntry[0].PartitionNumber ist 288.. Kann das sein?
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu
Online

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.114 Beiträge
 
Delphi 12 Athens
 
#10

Re: Union Übersetzung nach Pascal

  Alt 12. Mär 2007, 17:27
tja, das kommt wohl von den vielen Varianten -.-''

P := GetMemory(Size);
GetMem(P, Size);
P := SysGetMem(Size);
...

wobei GetMem eine Exception (EOutOfMemory) auslößt, wenn der gewpnschte Speicher nicht reserviert werden kann und die Anderen "nur" P=nil zurückliefern (also ohne Exception).


Was gibt DeviceIoControl für'n Fehler aus?
(bei 'nem Fehler wird nichts in den Record geschrieben, daher könnten auch die "komischen" Werte kommen ... standen halt vorher schon so drin)
Delphi-Quellcode:
Size := SizeOf(_DRIVE_LAYOUT_INFORMATION_EX) + SizeOf(_PARTITION_INFORMATION_EX) * 31;
GetMem(P, Size);
Try
  FillChar(P^, Size, 0);
  If DeviceIoControl(H, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, nil, 0,
    P, Size, OutBytes, nil) Then Begin
    
    ...

  End Else ShowMessage(SysErrorMessage(GetLastError));
Finally
  FreeMem(P);
End;
Und wie hast du dir eigentlich das Handle zur Partition geholt?
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 3  1 23   

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:40 Uhr.
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