15-05-2009, 09:32 PM
لقد حلت المشكلة بإذن الله وسوف اطرح الكود لعلى و عسى يحتاجه احد في يوما ما :
**
محمد
**
والسلام عليكم
كود :
Type
TTxtFileType = (txTxtOrBin{Default},
txUTF8, // Utf-8 encoding
txUNICODE, // Unicode ENCODING
txUNIBIG // unicode Big endian
);
TTxtFileSign = record
Code : TTxtFileType;
Sign : LongWord;
Mask : LongWord;
end;
const
TxtSignsCount = 3;
TxtSign_UTF8 : TTxtFileSign = (Code: txUTF8; Sign:$00BFBBEF; Mask: $00FFFFFF);
TxtSign_UNICODE : TTxtFileSign = (Code: txUNICODE; Sign:$0000FEFF; Mask: $FF00FFFF);
TxtSign_UNIBIG : TTxtFileSign = (Code: txUNIBIG; Sign:$0000FFFE; Mask: $00FFFFFF);
var
TxtFileSigns : array[0..2] of TTxtFileSign = (
(Code: txUTF8; Sign:$00BFBBEF; Mask: $00FFFFFF),
(Code: txUNICODE; Sign:$0000FEFF; Mask: $0000FFFF),
(Code: txUNIBIG; Sign:$0000FFFE; Mask: $0000FFFF));
function TypeOfTextfile(const filename: string): TTxtFileType;
var
Target : TFileStream;
Sign : LongWord;
N : integer;
begin
Target := TFileStream.Create(FileName, fmOpenRead);
try
{# 1st With BOOM #}
Target.Read(Sign, 4);
finally
Flux.Free;
end;
{# Default file is Ansi-encoding or Binary # }
result := txTxtOrBin;
for N := 0 to High(TxtFileSigns) do
begin
if (Sign and TxtFileSigns[N].Mask) = TxtFileSigns[N].Sign then
begin
result := TxtFileSigns[N].Code;
break;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
{# Op is an TOpenDialog # }
if not op.Execute then exit;
Case TypeOfTextfile(op.FileName) of
txTxtOrBin:Label2.Caption:='Ansi-Encoding or a Binary File';
txUTF8:Label2.Caption:='UTF-8 encoding ';
txUNICODE:Label2.Caption:='UNICODE encoding ';
txUNIBIG:Label2.Caption:='UNIBIG encoding ';
end;
end;**
محمد
**
والسلام عليكم

