Autor Beitrag
Enzo
Hält's aus hier
Beiträge: 11



BeitragVerfasst: Do 09.02.06 00:21 
Folgendes interessiert mich das es ihn delphi uebersetzt wird





ausblenden volle Höhe C#-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:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
void CFloatCnvtDlg::OnKillfocusHexEdit()
{
UINT nType;
int iLen, iCnt, iDataCtr;
unsigned char bData;

// Make a union of a float and it's four bytes.
union FloatHex{
unsigned char uData[4]; // Four bytes to hold an IEEE 754 float
float fValue; // The IEEE 754 float
}uConvert;

// Declare a string variable to hold the ASCII HEX form, and temp byte buffer.
CString strHex, strByte;


// Read user entered string from the Hex edit box.
m_HexEdit.GetWindowText(strHex);

// Convert HEX string to uppercase before conversion.
strHex.MakeUpper();

// Check for proper length of HEX string before conversion.
iLen = strHex.GetLength();

// Error checking - Check for invalid hex values.
// Display standard message box if non-Hex char found.
if (iLen == Cool {
for (iCnt=0; iCnt<iLen; ++iCnt){
bData = strHex.GetAt(iCnt);
if ( bData < '0' || (bData > '9' && bData < 'A') || bData > 'F' )
{
CString strCaption;
strCaption = "Bad Info";
nType = MB_ICONERROR;
CString strMsgText = "Please enter valid HEX string only.";
MessageBox( strMsgText, strCaption, nType); // Show msg box

// Setting iLen to -1 stops this loop and disables conversion.
iLen = -1;
}
}
}

// Conversion of ASCII Hex string to hex bytes.
if (iLen == Cool // MUST be 8 chars. (2 chars per byte, 4 bytes per float.)
{
//Loop through the HEX chars, and convert to byte values
//Because we read the float HEX string MSB to LSB, we must store
//the data MSB to LSB. So, iDataCtr was created to help readability.
iDataCtr = (iLen / 2) - 1//2 text chars per HEX byte. (0-based counter)

for (iCnt=0; iCnt<iLen; ++iCnt){
//Read high nibble char & store
bData = strHex.GetAt(iCnt); //Read high nibble char from string
if (bData > '9'//Convert ASCII A-F to decimal 10-15
bData -= 7;
bData <<= 4//move to high nib & store
uConvert.uData[iDataCtr] = bData;

// Get low nibble (next char in string)
++iCnt; //inc char ptr
bData = strHex.GetAt(iCnt); //get next char (low nibble)
if (bData > '9'//Convert ASCII A-F to decimal 10-15
bData -= 7;
bData -= '0'//convert from ASCII to hex
uConvert.uData[iDataCtr] |= bData;//merge hex value

--iDataCtr; //dec data union ptr
}
m_Float = uConvert.fValue; // Update the float edit variable
UpdateData(FALSE); // Update the dialog box (calls DDX).
}
// Error reporting. Skip this if an invalid Hex value was entered. (marked by iLen = -1)
else if (iLen != -1) {
// If we got here, either more than 8 or less than 8 chars were entered.
CString strCaption;
if (iLen < Cool { // Show msg for less than 8 chars
strCaption = "Not Enough Info";
nType = MB_ICONEXCLAMATION;
}
if (iLen > Cool { // Show msg for more than 8 chars
strCaption = "Too Much Info!";
nType = MB_ICONQUESTION;
}
CString strMsgText = "Please enter 4 Hex bytes";
MessageBox( strMsgText, strCaption, nType); // Show msg box
}

}






Ich hoffe Ihr koennt mir Helfen


Gruss enzo

Moderiert von user profile iconChristian S.: C#-Tags hinzugefügt
afk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 102

Win 2K, Win XP
Delphi 2006 Arch., Delphi 6 Ent., MS-SQL 2005 & 2000
BeitragVerfasst: Do 09.02.06 01:24 
ausblenden 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:
procedure CFloatCnvtDlg.OnKillfocusHexEdit;
var
  uData: Integer;
  fValue: Single absolute uData;
  strHex: String;
  iLen: Integer;
begin
  strHex:=m_HexEdit.Text;
  iLen:=Length(strHex);
  If iLen = 8 then
  begin
    try
      uData:=StrToInt('$'+strHex);
    except
      MessageDlg('Please enter valid HEX string only.', mtError, [mbOK], 0);
    end;
  end else begin
    If iLen > 8 then MessageDlg('Not enough info, please enter 4 HEX bytes.', mtError, [mbOK], 0)
                else MessageDlg('Too much info, please enter 4 HEX bytes.', mtError, [mbOK], 0);
  end;
  m_Float:=fValue;   // Update the float edit variable
  UpdateData(FALSE); // Update the dialog box (calls DDX).
end;

Ich habe das Ganze bei gleichem Funktionsumfang mit den Möglichkeiten in Delphi entsprechend vereinfacht, aber die Namen der Variablen beibehalten, soweit das möglich war. Nur die letzten beiden Zeilen habe ich so gelassen, wie sie waren (allerdings in Delphi-konformer Schreibweise), da damit externe Daten bzw. Methoden beeinflußt werden.

Aber geht das nicht auch in C++ viel einfacher ?

Gruß Axel

_________________
Man muß sparn wo mn knn !
Enzo Threadstarter
Hält's aus hier
Beiträge: 11



BeitragVerfasst: Do 09.02.06 15:11 
Titel: C++ nach delphi
Hallo Axel

erstmals danke fuer deine Hilfe.

Ich fuege das Komplette Programm und es ist ihn C++ , es ist ein Float Converter.

Was ich brauche ihn delphi, ist die funktion um meine Hex daten ihn Float Ieee zu konvertieren.

Das oben genante Programm hat es aber leider meine Kentnisse ihn C++ nicht gut sind,

bitte ich um Hilfe.


Gruss enzo
Einloggen, um Attachments anzusehen!