mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-06 10:40:50 +02:00
use StrToQWord instead of StrToInt64 to safely convert string to QWord
git-svn-id: trunk@8447 -
This commit is contained in:
parent
2940e62358
commit
f6c2971980
@ -33,10 +33,12 @@ unit PropEdits;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, TypInfo, SysUtils, LCLProc, Forms, Controls, GraphType, Graphics,
|
||||
StdCtrls, Buttons, ComCtrls, Menus, LCLType, ExtCtrls, LCLIntf, Dialogs,
|
||||
Grids, EditBtn, PropertyStorage, TextTools, FrmSelectProps, ColumnDlg,
|
||||
FileUtil, ObjInspStrConsts;
|
||||
Classes, TypInfo, SysUtils,
|
||||
FPCAdds, // for StrToQWord in older fpc versions
|
||||
LCLProc, Forms, Controls, GraphType,
|
||||
Graphics, StdCtrls, Buttons, ComCtrls, Menus, LCLType, ExtCtrls, LCLIntf,
|
||||
Dialogs, Grids, EditBtn, PropertyStorage, TextTools, FrmSelectProps,
|
||||
ColumnDlg, FileUtil, ObjInspStrConsts;
|
||||
|
||||
const
|
||||
MaxIdentLength: Byte = 63;
|
||||
@ -449,6 +451,7 @@ type
|
||||
TQWordPropertyEditor = class(TInt64PropertyEditor)
|
||||
public
|
||||
function GetValue: ansistring; override;
|
||||
procedure SetValue(const NewValue: ansistring); override;
|
||||
end;
|
||||
|
||||
{ TFloatPropertyEditor
|
||||
@ -2821,6 +2824,11 @@ begin
|
||||
Result := IntToStr(QWord(GetInt64Value));
|
||||
end;
|
||||
|
||||
procedure TQWordPropertyEditor.SetValue(const NewValue: ansistring);
|
||||
begin
|
||||
SetInt64Value(StrToQWord(NewValue));
|
||||
end;
|
||||
|
||||
{ TFloatPropertyEditor }
|
||||
|
||||
function TFloatPropertyEditor.AllEqual: Boolean;
|
||||
|
@ -22,11 +22,18 @@
|
||||
unit FPCAdds;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
{$if defined(VER2_0_0) or defined(VER_2_0_1) or defined(VER_2_0_2)}
|
||||
{$DEFINE FPC_HAS_NO_STRTOQWORD}
|
||||
{$ENDIF}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils;
|
||||
Classes, SysUtils
|
||||
{$IFDEF FPC_HAS_NO_STRTOQWORD}
|
||||
,sysconst
|
||||
{$ENDIF}
|
||||
;
|
||||
|
||||
// current TStream calculates in int64, old in longint
|
||||
type
|
||||
@ -43,6 +50,10 @@ function ExceptFrameCount: Longint;
|
||||
function ExceptFrames: PPointer;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF FPC_HAS_NO_STRTOQWORD}
|
||||
function StrToQWord(const s: string): QWord;
|
||||
{$ENDIF}
|
||||
|
||||
implementation
|
||||
|
||||
function StrToWord(const s: string): word;
|
||||
@ -117,6 +128,15 @@ begin
|
||||
end;
|
||||
{$ENDIF}{$ENDIF}
|
||||
|
||||
{$IFDEF FPC_HAS_NO_STRTOQWORD}
|
||||
function StrToQWord(const s: string): QWord;
|
||||
var Error: word;
|
||||
begin
|
||||
Val(S, result, Error);
|
||||
if Error <> 0 then raise EConvertError.createfmt(SInvalidInteger,[S]);
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF VER2_0_0}{$IFDEF win32}
|
||||
initialization
|
||||
InitWin32Widestrings;
|
||||
|
Loading…
Reference in New Issue
Block a user