Einzelnen Beitrag anzeigen

Kas Ob.

Registriert seit: 3. Sep 2023
353 Beiträge
 
#9

AW: Datei-Transfer mit DragAndDropComponentSuite

  Alt 14. Jul 2024, 09:08
@himitsu

I am not sure if i do understand the problem, your software problem with drag and drop and outlook with lost/cutshort characters...

But looking at the attached project i see this strange lines
Code:
class function TForm25.GetLongName(Filename: string): string;
begin
  SetLength(Result, GetLongPathName(PChar(Filename), nil, 0) - 1);
  GetLongPathName(PChar(Filename), PChar(Result), Length(Result) + 1);
end;

class function TForm25.GetShortName(Filename: string): string;
begin
  SetLength(Result, GetShortPathName(PChar(Filename), nil, 0) - 1);
  GetShortPathName(PChar(Filename), PChar(Result), Length(Result) + 1);
end;
Why the "-1" ?
And more importantly :
Why you are not trimming after the second call based on the GetxxxxPathName result ?

My suggestion is to fix that then repeat your test with the customers:
The flow for this type of API use, should always be one call to decide the length, then allocate then call again then trim, don't cut corners, and never trust the first call for the length as it might change between the two calls.

When in doubt for Unicode and UTF8 for the real length in bytes against chars (WideChar, UTF8Char, UTF16Char....) change the allocate step mentioned above to RequiredLength*4, this will be removed with the last trim, in other words trade "little more work and allocation" against "will work always", also this will remove the need to keep tracking of the different APIs which some do return the 0 terminated and some doesn't, so you can with extra big allocated put the null char your self before the trim, and either keep it or remove it, based on the use case.
Kas
  Mit Zitat antworten Zitat