cebasso
asked on
Delphi DWORD and/or comparison
Hello!
how to compare dword with AND / OR statment?
example
const
DWORD_1 = $00060000;
DWORD_2 = $00F80000;
DWORD_3 = $00010000;
DWORD_5 = $0000F000;
DWORD_6 = $000000FF;
DWORD_7 = $002000FF;
function CheckDWORD(dwBuff: DWORD): String;
begin
if (dwBuff or DWORD_1) = DWORD_1 then
Result := 'DWORD_1,';
if (dwBuff or DWORD_2) = DWORD_2 then
Result := Result + 'DWORD_2,';
if (dwBuff or DWORD_3) = DWORD_3 then
Result := Result + 'DWORD_3,';
if (dwBuff or DWORD_4) = DWORD_4 then
Result := Result + 'DWORD_4,';
if (dwBuff or DWORD_5) = DWORD_5 then
Result := Result + 'DWORD_5,';
if (dwBuff or DWORD_6) = DWORD_6 then
Result := Result + 'DWORD_6';
end;
var
dwBuff: DWORD;
begin
dwBuff := DWORD_3;
//below OK return only "DWORD_3,"
ShowMessage(CheckDWORD(dwB uff));
//but here
dwBuff := DWORD_2 and DWORD_5;
ShowMessage(CheckDWORD(dwB uff));
//return ALL the statments "DWORD_1, DWORD_2, DWORD_3," etc...
//and was supposed to return only "DWORD2, DWORD5" not ALL :(
How can i do?
Thanks!
Best Regards,
Carlos
how to compare dword with AND / OR statment?
example
const
DWORD_1 = $00060000;
DWORD_2 = $00F80000;
DWORD_3 = $00010000;
DWORD_5 = $0000F000;
DWORD_6 = $000000FF;
DWORD_7 = $002000FF;
function CheckDWORD(dwBuff: DWORD): String;
begin
if (dwBuff or DWORD_1) = DWORD_1 then
Result := 'DWORD_1,';
if (dwBuff or DWORD_2) = DWORD_2 then
Result := Result + 'DWORD_2,';
if (dwBuff or DWORD_3) = DWORD_3 then
Result := Result + 'DWORD_3,';
if (dwBuff or DWORD_4) = DWORD_4 then
Result := Result + 'DWORD_4,';
if (dwBuff or DWORD_5) = DWORD_5 then
Result := Result + 'DWORD_5,';
if (dwBuff or DWORD_6) = DWORD_6 then
Result := Result + 'DWORD_6';
end;
var
dwBuff: DWORD;
begin
dwBuff := DWORD_3;
//below OK return only "DWORD_3,"
ShowMessage(CheckDWORD(dwB
//but here
dwBuff := DWORD_2 and DWORD_5;
ShowMessage(CheckDWORD(dwB
//return ALL the statments "DWORD_1, DWORD_2, DWORD_3," etc...
//and was supposed to return only "DWORD2, DWORD5" not ALL :(
How can i do?
Thanks!
Best Regards,
Carlos
a bit more, splitting the DWORD ....
{
// high byte // lower byte
x_hi := hi(x_dw); x_lo := lo(x_dw);
y_hi := hi(y_dw); x_lo := lo(y_dw);
ShowMessage( IntToStr(x_hi)+'.'+ IntToStr(X_lo));
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
maybe this can help
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function CheckDWORD(dwBuff: string): String;
end;
var
Form1: TForm1;
const
DWORD_1 = $00060000;
DWORD_2 = $00F80000;
DWORD_3 = $00010000;
DWORD_5 = $0000F000;
DWORD_6 = $000000FF;
DWORD_7 = $002000FF;
implementation
{$R *.dfm}
function TForm1.CheckDWORD(dwBuff: string): String;
var
sl:TStringList;
I: Integer;
begin
sl:=TStringList.Create;
Result := '';
sl.CommaText := dwBuff;
for I := 0 to sl.Count-1 do
begin
case StrToInt(sl[i]) of
DWORD_1:Result := Result + 'DWORD_1,';
DWORD_2:Result := Result + 'DWORD_2,';
DWORD_3:Result := Result + 'DWORD_3,';
DWORD_5:Result := Result + 'DWORD_5,';
DWORD_6:Result := Result + 'DWORD_6,';
DWORD_7:Result := Result + 'DWORD_7,';
end;
end;
Result := copy(Result,1,length(Resul t)-1);
sl.free;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
s:string;
begin
s := IntToStr(DWORD_3);
ShowMessage(CheckDWORD(s)) ;
s := IntToStr(DWORD_2)+','+IntT oStr(DWORD _5);
ShowMessage(CheckDWORD(s)) ;
end;
end.
--------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function CheckDWORD(dwBuff: string): String;
end;
var
Form1: TForm1;
const
DWORD_1 = $00060000;
DWORD_2 = $00F80000;
DWORD_3 = $00010000;
DWORD_5 = $0000F000;
DWORD_6 = $000000FF;
DWORD_7 = $002000FF;
implementation
{$R *.dfm}
function TForm1.CheckDWORD(dwBuff: string): String;
var
sl:TStringList;
I: Integer;
begin
sl:=TStringList.Create;
Result := '';
sl.CommaText := dwBuff;
for I := 0 to sl.Count-1 do
begin
case StrToInt(sl[i]) of
DWORD_1:Result := Result + 'DWORD_1,';
DWORD_2:Result := Result + 'DWORD_2,';
DWORD_3:Result := Result + 'DWORD_3,';
DWORD_5:Result := Result + 'DWORD_5,';
DWORD_6:Result := Result + 'DWORD_6,';
DWORD_7:Result := Result + 'DWORD_7,';
end;
end;
Result := copy(Result,1,length(Resul
sl.free;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
s:string;
begin
s := IntToStr(DWORD_3);
ShowMessage(CheckDWORD(s))
s := IntToStr(DWORD_2)+','+IntT
ShowMessage(CheckDWORD(s))
end;
end.
procedure TForm1.AndButtonClick(Send
var x_dw, y_dw : Dword ;
x_hi,x_lo, y_hi, y_lo : Word;
highword, lowWord : Word;
begin
x_dw := $00060000;
y_dw := $00060000;
{
// high byte // lower byte
x_hi := hi(x_dw); x_lo := lo(x_dw);
y_hi := hi(y_dw); x_lo := lo(y_dw);
ShowMessage( IntToStr(x_hi)+'.'+ IntToStr(X_lo));
}
highword:=x_dw div 65536;
lowword:=x_dw mod 65536;
ShowMessage( IntToStr(highword)+'.'+ IntToStr(lowword));
end;