Recent

Author Topic: Convert Errors Delphi -> Lazarus  (Read 13325 times)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Convert Errors Delphi -> Lazarus
« Reply #15 on: August 22, 2019, 03:38:49 pm »
Unicode is something that a whole book can be written around. Sufficient to say that Lazarus is a mix of old and new delphi and then some.

However your first problem is easy to fix:

I Think this is for now not my problem but thanks for the help.

Actually i have these problems on my converted project:

1. A malfunction from "movefile": Lazarus has problems with umlauts.  So if i try to move a file with umlauts, it doesn't work. Is there any way to fix it (or have i work without umlauts)?

Movefile is movefileA on Lazarus and movefilew on Delphi 2009 and later.
string is ansistring containing utf8 on lazarus (8-bit unicode mostly) and  unicodestring (16-bit unicode) on Delphi 2009 and later. Conversion between both is pretty seamless.

Solution: use movefilew and a wrapper procedure:

Code: Pascal  [Select][+][-]
  1. procedure mymovefile(src,target:unicodestring);
  2. begin
  3.  movefilew (pwidechar(src),pwidechar(dest),.... other params);
  4. end;

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Convert Errors Delphi -> Lazarus
« Reply #16 on: August 22, 2019, 06:30:56 pm »
Code: Pascal  [Select][+][-]
  1. procedure mymovefile(src,target:unicodestring);
  2. begin
  3.  movefilew (pwidechar(src),pwidechar(dest),.... other params);
  4. end;

Code: Pascal  [Select][+][-]
  1. procedure movefile(src,target:unicodestring);overload;
  2. begin
  3.  movefilew (pwidechar(src),pwidechar(dest),.... other params);
  4. end;
Wouldn't that work yet?
Specialize a type, not a var.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Convert Errors Delphi -> Lazarus
« Reply #17 on: August 22, 2019, 07:48:01 pm »
Code: Pascal  [Select][+][-]
  1. procedure mymovefile(src,target:unicodestring);
  2. begin
  3.  movefilew (pwidechar(src),pwidechar(dest),.... other params);
  4. end;

Code: Pascal  [Select][+][-]
  1. procedure movefile(src,target:unicodestring);overload;
  2. begin
  3.  movefilew (pwidechar(src),pwidechar(dest),.... other params);
  4. end;
Wouldn't that work yet?

No.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Convert Errors Delphi -> Lazarus
« Reply #18 on: August 22, 2019, 08:50:18 pm »
Sigh.  :D
Specialize a type, not a var.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Convert Errors Delphi -> Lazarus
« Reply #19 on: August 22, 2019, 09:57:54 pm »
RenameFiles also moves files - vice versa it's old Unix tradition.

And RenameFileUTF8 hopefully converts your umlauts, Umlaute (or whatever)  correct.

From LazFileUtils.xml:

RenameFileUTF8

          Renames a file to the specified value
          RenameFileUTF8 is a Boolean function used to rename a file to the specified new value.
          For the Windows enviroment, MoveFileW is called to rename the file using the values         
          specified in OldName and NewName. For UNIX-like enviroments, DeleteFile in SysUtils is     
          called to delete the specified file name. InvalidateFileStateCache is also called.
         
           The return value is True if the file is renamed successfully.


Winni
« Last Edit: August 22, 2019, 10:20:43 pm by winni »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Convert Errors Delphi -> Lazarus
« Reply #20 on: August 22, 2019, 10:39:00 pm »
Sigh.  :D

I was thinking that it won't work because you must match unicodestring,unicodestring prototype to trigger the overload. Any combination of strings is down converted to the primary 1-byte string type.

However the windows version is p(ansi)char, not ansistring. So my guess you will just get a "don't know which overload to call".

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Convert Errors Delphi -> Lazarus
« Reply #21 on: August 22, 2019, 10:42:41 pm »
RenameFiles also moves files - vice versa it's old Unix tradition.

And RenameFileUTF8 hopefully converts your umlauts, Umlaute (or whatever)  correct.

With FPC 3.0, RTL renamefile should work fine and fileutils -UTF8 versions are legacy. However this thread is about windows unit, which is a pure windows api header which does not play nice with Lazarus' string conventions. You need to call the -W versions in that case.

But afaik Windows rename (and move too) does not move files across volumes, unless options are given.

IIRC I used MoveFileExW(pwidechar(src),pwidechar(s2),MOVEFILE_COPY_ALLOWED)  to force it to move across volumes.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Convert Errors Delphi -> Lazarus
« Reply #22 on: August 22, 2019, 11:12:20 pm »
Hi!

I was not quiet shure, but I remembered to move file between different disks with renamefile in windows.

And indeed: If you look in winlazfileutils.inc then you see that RenameFileUTF8 does nothing but to call MoveFileW!

Line  230 ff:

Code: Pascal  [Select][+][-]
  1. function RenameFileUtf8(const OldName, NewName: String): Boolean;
  2. begin
  3.   Result:=MoveFileW(PWideChar(UTF8Decode(OldName)), PWideChar(UTF8Decode(NewName)));
  4. end;                                                                    
  5.  

Winni

Moombas

  • New Member
  • *
  • Posts: 38
Re: Convert Errors Delphi -> Lazarus
« Reply #23 on: August 23, 2019, 08:29:38 am »
Solution: use movefilew and a wrapper procedure:

Code: Pascal  [Select][+][-]
  1. procedure mymovefile(src,target:unicodestring);
  2. begin
  3.  movefilew (pwidechar(src),pwidechar(dest),.... other params);
  4. end;

Thanks a lot, this works fine.
The path is the destination but you should never lose sight of the destination on the way.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Convert Errors Delphi -> Lazarus
« Reply #24 on: August 23, 2019, 09:24:27 am »
All differences have been found and the project now works as in Delphi.
A second project has been transfered succesfully too.

Is there a way that lazarus removes the namespaces (e.g.  "System.") by itself when it transfers the project?

Actually you do not have to remove them at all. You can use the -FN compiler option to add the namespaces.
https://wiki.freepascal.org/FPC_New_Features_3.0#Delphi-like_namespaces_units.

(This feature somehow went under the radar of lazarus developers)
As marcov already wrote the -FN option was only added in 3.1.1 and is thus only available there (I should really add an entry for the 3.2 features page...).

Also the switch wouldn't be able to solve anything, because the units would need to exist with the namespaces which they don't.

Moombas

  • New Member
  • *
  • Posts: 38
Re: Convert Errors Delphi -> Lazarus
« Reply #25 on: August 23, 2019, 10:47:56 am »
So, i got the next problem:

Identifier not found: ReadDirectoryChangesW

Is there a Lazarus specific Unit i have to add or an other function to use?
The path is the destination but you should never lose sight of the destination on the way.

nouzi

  • Sr. Member
  • ****
  • Posts: 296
Re: Convert Errors Delphi -> Lazarus
« Reply #26 on: August 23, 2019, 11:10:26 am »
So, i got the next problem:

Identifier not found: ReadDirectoryChangesW

Is there a Lazarus specific Unit i have to add or an other function to use?
See this
https://forum.lazarus.freepascal.org/index.php?topic=44903.0
My English is  bad
Lazarus last version free pascal last version
Lazarus trunk  free pascal trunk 
System : Linux mint  64bit  Windows 7 64bit

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Convert Errors Delphi -> Lazarus
« Reply #27 on: August 23, 2019, 11:27:27 am »
(note that development  FPC versions do have it now)

Moombas

  • New Member
  • *
  • Posts: 38
Re: Convert Errors Delphi -> Lazarus
« Reply #28 on: August 23, 2019, 11:50:01 am »
ok, got it now, added it to project instead of the externeal unit -.-

But i Get an error to RDCWProcessMonitor (included in DirMonitor):

Code: Pascal  [Select][+][-]
  1. procedure TProcessMonitor.Execute;
  2. var
  3.   state:cardinal;
  4.   quit:boolean;
  5.   parent:TDirMonitor;
  6.   numBytes: DWORD;
  7. begin
  8.   { Place thread code here }
  9.   quit:=false;
  10.   parent:=TDirMonitor(self.FProRef);
  11.   while (not quit) do
  12.   begin
  13.     GetQueuedCompletionStatus( parent.FCompletionPort, numBytes, state, parent.FPOverlapped, INFINITE);  //Got LongWord expected QWord
  14. //...
  15.  

Edited it now to QWord and its working.
« Last Edit: August 23, 2019, 12:12:20 pm by Moombas »
The path is the destination but you should never lose sight of the destination on the way.

Moombas

  • New Member
  • *
  • Posts: 38
Re: Convert Errors Delphi -> Lazarus
« Reply #29 on: August 23, 2019, 02:52:24 pm »
Ok, next there are two problems:

1. The application Crashes when following Code is processed:
Code: Pascal  [Select][+][-]
  1. procedure TTools.ToolbarSet(ToolE : TLabeledEdit; ToolI : TImage; ToolC : TCheckbox; ToolN : TLabeledEdit; ToolB : TButton);
  2. var
  3.   i, bs, lc : integer;
  4.   icon   : TIcon;
  5.   Filter : LPWord;
  6. begin
  7.   bs     := 0;
  8.   lc     := 0;
  9.  
  10.   if ToolE.Text <> '' then
  11.   begin
  12.     Icon := TIcon.Create;
  13.     try
  14.       ToolC.Checked := True;
  15.       for i := 1 to length(ToolE.Text) do
  16.       begin
  17.         if ToolE.Text[i] = '\' then
  18.         begin
  19.           inc(bs);
  20.         end;
  21.         if ToolE.Text[i] = ' ' then
  22.         begin
  23.           inc(lc);
  24.         end;
  25.       end;
  26.       if ToolN.Text <> '' then
  27.       begin
  28.         ToolB.Caption := ToolN.Text
  29.       end else
  30.       begin
  31.            ToolB.Caption := split(ToolE.Text, '\', bs - 1 + lc);
  32.       end;
  33.  
  34.       Icon.Handle := ExtractAssociatedIcon (hInstance, PChar(ToolE.Text), Filter);  //Crashes here. But Why? In Delphi its working nice.
  35.  
  36.       ToolI.Picture.Icon := icon;
  37.       if GetFileVersion(ToolE.Text) <> 'No version specification' then
  38.         ToolI.Hint := GetFileVersion(ToolE.Text);
  39.     finally
  40.       ToolI.show;
  41.       icon.Free;
  42.     end;
  43.     ToolB.Show;
  44.   end else
  45.   begin
  46.     ToolI.hide;
  47.     ToolB.Hide;
  48.     ToolC.Checked := False;
  49.   end;
  50. end;  
  51.  

2.  The SHA256 coding doesn't work. Below code works fine in Delphi:
Code: Pascal  [Select][+][-]
  1. var
  2.   newPW : String;
  3. begin
  4.   newPW := ThashSHA2.GetHashString(newPW), SHA256);
  5. end;
  6.  

3. Ini doen't read as Unicode (again the Problem with the umlauts):
Code: Pascal  [Select][+][-]
  1. Delay.Text          := Ini.ReadString ('Install' , 'Delay'               , '15');  
  2.  
« Last Edit: August 23, 2019, 03:49:00 pm by Moombas »
The path is the destination but you should never lose sight of the destination on the way.

 

TinyPortal © 2005-2018