Re: StrFormatByteSize64: how to use it?



Matteo Riso wrote:
procedure TForm1.DimFile(Siz: Int64): string;
var
filesize: PAnsiChar;
begin
StrFormatByteSize64(Siz, FileSize,255);
....
end;

When I execute this program StrFormatByteSize64 converts the value to string, but it raises also an "Access Violation" error.

You haven't reserved any memory for your PAnsiChar, it's just a pointer to nowhere in particular. Try this:


procedure TForm1.DimFile(Siz: Int64): string;
var
filesize: string;
begin
setlength(filesize,255);
setlength(filesize,StrFormatByteSize64(Siz, pchar(FileSize),length(filesize)));
end;


Cheer,
Nicholas Sherlock
.



Relevant Pages

  • Re: Fortran-compiled DLLs in Python
    ... WindowsError: exception: access violation ... > I do not know how fortran passes this parameter, ... strings may pass a "string descriptor", ...
    (comp.lang.python)
  • Re: Way around error?
    ... The code works if the string is allocated from the ... attempted to convert a const value to a non-const pointer. ... >I get the access violation at the first attempt to modify the string. ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • AnsiString on Heap.
    ... AnsiString is inside the form. ... If no string is assigned to it it will still give an access violation making ...
    (alt.comp.lang.borland-delphi)
  • Re: Inline Assembly
    ... your stosb writes to *StringWorked, you're getting an access violation. ... Presumably you mean to do some kind of transform on the string while copying ... writing this code in C or C++, and it'll be less portable and a lot less ...
    (microsoft.public.vc.language)
  • Re: Way around error?
    ... The hope was to design a method that was 'universal' - since the string ... Balboos wrote: ... > I get the access violation at the first attempt to modify the string. ...
    (microsoft.public.vc.mfc)