View Issue Details

IDProjectCategoryView StatusLast Update
0002109JEDI VCL00 JVCL Componentspublic2004-09-04 02:22
ReportercraigismAssigned ToAHUser 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0002109: JvFormStorage and saving properties as doubles
DescriptionDrop a JvSpinEdit1.value (set to integer) on a form, store the property and run.
This will cause an access violation error on exit.
Also all properties as doubles will error.
-
Craig
Additional InformationThis is easy to reproduce with the example above.

Some more info:
Also all '.value' properties seem to cause the same issue.

function TJvCustomAppIniStorage.DoReadBinary(const Path: string; var
Buf; BufSize: Integer): Integer;
var
  Section: string;
  Key: string;
  Value: string;
begin
  SplitKeyPath(Path, Section, Key);
  if ValueExists(Section, Key) then
  begin
    Value := ReadValue(Section, Key);
    Result := BinStrToBuf(Value, Buf, BufSize); <<<<<<<
  end
  else
    Result := 0;
end;

procedure TJvCustomAppIniStorage.DoWriteBinary(const Path: string; const
Buf; BufSize: Integer);
var
  Section: string;
  Key: string;
begin
  SplitKeyPath(Path, Section, Key);
  WriteValue(Section, Key, BufToBinStr(Buf, BufSize)); <<<<<<
end;


My case and the offending functions getting called:

These functions are causing access violations with a Preview component
(not JVCL).
When I try to add and close my application I get errors.
PreviewPrinter.TextOptions (collection see below)
PreviewPrinter.ZoomValue (100 as a double)

These works:
PreviewPrinter.ZoomOption (Combo List)
PreviewPrinter.Tag

This all had worked before a recent JVCL update

function BinStrToBuf(Value: string; var Buf; BufSize: Integer): Integer;
var
  P: PChar;
begin
  if Odd(Length(Value)) then
    Value := cNullDigit + Value;
  if (Length(Value) div 2) < BufSize then
    BufSize := Length(Value) div 2;
  Result := 0;
  P := PChar(Value);
  while BufSize > 0 do
  begin
    PChar(Buf)[Result] := Chr(StrToInt('$' + P[0] + P[1])); // here
<<<<<<<
    Inc(Result);
    Dec(BufSize);
    Inc(P, 2);
  end;
end;

function BufToBinStr(const Buf; BufSize: Integer): string;
var
  P: PChar;
  S: string;
begin
  SetLength(Result, BufSize * 2);
  P := PChar(Result);
  Inc(P, (BufSize - 1) * 2); // Point to end of string ^
  while BufSize > 0 do
  begin
    S := IntToHex(Ord(PChar(Buf)[BufSize]), 2); // <<<<<<<<< Buf has 'no
value'
    P[0] := S[1];
    P[1] := S[2];
    Dec(P, 2);
    Dec(BufSize);
  end;
end;



TTextOptions = class(TPersistent)
   protected
      FDrawStyle : TDrawStyle;
      FLeft : double;
      FTop : double;
      FRight : double;
      FBot : double;
      FBodyFont : TFont;
      FHdrFont : TFont;
      FFtrFont : TFont;
      FPageFont : TFont;
      FHeader : string;
      FFooter : string;
      FHdrMarg : double;
      FFtrMarg : double;
      FHdrAlign : TAlignment;
      FFtrAlign : TAlignment;
      FPrtPage : TPrintPageNumber;
      FPageAlign : TAlignment;
      FPageText : string;
      FPageMacroText : string;
      procedure SetBodyFont(Val: TFont);
      procedure SetHdrFont(Val: TFont);
      procedure SetFtrFont(Val: TFont);
      procedure SetPageFont(Val: TFont);
   public
      constructor Create;
      destructor Destroy; override;
      procedure Assign(Source: TPersistent); override;
   published
      property DrawStyle: TDrawStyle read FDrawStyle write
FDrawStyle;
      property MarginLeft: double read FLeft write FLeft;
      property MarginTop: double read FTop write FTop;
      property MarginRight: double read FRight write FRight;
      property MarginBottom: double read FBot write FBot;
      property BodyFont: TFont read FBodyFont write SetBodyFont;
      property HeaderFont: TFont read FHdrFont write SetHdrFont;
      property FooterFont: TFont read FFtrFont write SetFtrFont;
      property PageNumFont: TFont read FPageFont write SetPageFont;
      property Header: string read FHeader write FHeader;
      property Footer: string read FFooter write FFooter;
      property HeaderMargin: double read FHdrMarg write FHdrMarg;
      property FooterMargin: double read FFtrMarg write FFtrMarg;
      property HeaderAlign: TAlignment read FHdrAlign write
FHdrAlign;
      property FooterAlign: TAlignment read FFtrAlign write
FFtrAlign;
      property PrintPageNumber: TPrintPageNumber read FPrtPage write
FPrtPage;
      property PageNumAlign: TAlignment read FPageAlign write
FPageAlign;
      property PageNumText: string read FPageText write FPageText;
      property PageMacroText: string read FPageMacroText write
FPageMacroText;
   end;

TagsNo tags attached.

Activities

2004-09-01 14:50

 

FormPlacementTest.zip (3,859 bytes)

jfudickar

2004-09-01 14:51

developer   ~0005137

I see the bug and added a sample, but i didn't understand the code in BufToBinStr :-(, so anyone else please.

jfudickar

2004-09-01 14:52

developer   ~0005138

You can prevent it temporary by setting the StorageOptions.FloatAsString property of the IniFileStorage to true.

AHUser

2004-09-04 02:12

developer   ~0005175

There were two bugs in the BufToBinStr and BinStrToBuf methods.
1. The BufSize is 1-based, but used in a zero-based PChar.
2. The Buf is converted to a PChar which is wrong. The address of Buf must be converted to PChar, means a PChar(@Buf) (the at char is important).

I have fixed thin in CVS. Now I will try to create a testcase for the collection. It is always easier if a demo is added for each bug so we can start fixing the bug by simply starting the debugger. So I must invest some time for a demo that meight work because it is a wrong testcase.

Issue History

Date Modified Username Field Change
2004-09-01 05:29 craigism New Issue
2004-09-01 14:50 jfudickar File Added: FormPlacementTest.zip
2004-09-01 14:51 jfudickar Note Added: 0005137
2004-09-01 14:51 jfudickar Status new => acknowledged
2004-09-01 14:52 jfudickar Note Added: 0005138
2004-09-04 02:12 AHUser Note Added: 0005175
2004-09-04 02:22 AHUser Status acknowledged => resolved
2004-09-04 02:22 AHUser Resolution open => fixed
2004-09-04 02:22 AHUser Assigned To => AHUser