[Lazarus] -FcUTF8,-dEnableUTF8 create problem

FreeMan freeman35 at delphiturkiye.com
Tue Feb 24 09:35:37 CET 2015


On 22.02.2015 20:37, Mattias Gaertner wrote:
> Post a complete example and someone can find out.
>
> Mattias
code block is not mine, I was find in this link.
http://lists.lazarus.freepascal.org/pipermail/lazarus/2013-November/084198.html

function AnyProgramVersion(const sProgram: string; Out vv: PTVersion) :Boolean;
const
   WIN_EXE: String = 'MZ';
   LINUX_EXE: String = #127 + 'ELF';
var
   wFileStr: TFileStream;
   RS : TResources;
   E : TWinPEImageResourceReader=nil;
   EL : TElfResourceReader=nil;
   VR : TVersionResource;
   I : Integer;
   {$IFDEF WINCE}
   wProgram: WideString;
   {$ELSE}
   wProgram: String;
   {$ENDIF}
   ar: array[0..4] of byte;
   ExecType: char;
begin
   Result := False;
   vv := New(PTVersion);
   with vv^ do begin
     Major:= -1;
     Minor := 0;
     Release := 0;
     Build := 0;
   end;
   if sProgram = EmptyStr then
     wProgram := ParamStr(0)
   else
     wProgram := sProgram;
   if not FileExists(wProgram) then begin
     // program name without path, assume directory of executing program
     if Pos(DirectorySeparator, wProgram) = 0 then begin
       wProgram := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0))) + sProgram;
       if not FileExists(wProgram) then
         Exit;
     end else
       // no path delimiter, get out
       Exit;
   end else
     wProgram := sProgram;
   wFileStr := TFileStream.Create(sProgram, fmOpenRead);
   try
     // check what kind of executable an get resources accordingly
     wFileStr.Read(ar, 4);
   Finally
     wFileStr.Free;
   end;
   if CompareMem(@(ar), Pchar(WIN_EXE), 2) then
     ExecType := 'W'
   else
   if CompareMem(@(ar), Pchar(LINUX_EXE), 4) then
     ExecType := 'L'
   else
     Exit;
   RS:=TResources.Create;
   try
     try
       if ExecType = 'W' then begin
         E := TWinPEImageResourceReader.Create;
         Rs.LoadFromFile(wProgram, E);
       end else begin
         EL := TElfResourceReader.Create;
         Rs.LoadFromFile(wProgram, EL);
       end;
     finally
       if Assigned(E) then
         E.Free;
       if Assigned(EL) then
         EL.Free;
     end;
     VR:=Nil;
     I:=0;
     While (VR=Nil) and (I < RS.Count) do begin
       if RS.Items[i] is TVersionResource then
         VR := TVersionResource(RS.Items[i]);
       Inc(I);
     end;
     if VR <> Nil then begin
       with vv^ do begin
         Major:= VR.FixedInfo.FileVersion[0];
         Minor := VR.FixedInfo.FileVersion[1];
         Release := VR.FixedInfo.FileVersion[2];
         Build := VR.FixedInfo.FileVersion[3];
       end;
       Result := True
     End ;
   Finally
     RS.FRee;
   end;
end;

{$IFDE


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20150224/6f496125/attachment-0003.html>


More information about the Lazarus mailing list