T
tianyu717
Unregistered / Unconfirmed
GUEST, unregistred user!
我写的一个单元,但在其它单元中调用 AppIni:=TAppIni.Create; 出现错误提示。
‘Acess violation at address 004c4b9e in module 'tian.exe'.read of address FFFFFFFF’
请求大侠帮忙。
unit RegUnit;
interface
uses
IniFiles, SysUtils, Forms, Graphics, Main;
type
TAppIni=class
private
FileName:string;
public
//类成员函数
constructor Create;
destructor Destroy;override;
end;
const
csWidth='Width';
csHeight='Height';
csLeft='Left';
csTop='Top';
csState='State';
csVisible='Visible';
csColor='Color';
csFontName='FontName';
csFontSize='FontSize';
csFontColor='FontColor';
csFontStyle='FontStyle';
csReadOnly='Edit';
csWordWrap='WordWrap';
var
AppIni:TAppIni;
implementation
constructor TAppIni.Create;
var
i,n:integer;
Ini:TIniFile;
pStyles
ointer;
s:string;
begin
//求出应用程序的INI文件名
FileName:=Application.ExeName;
n:=Length(FileName);
FileName[n-2]:='i';
FileName[n-1]:='n';
FileName[n] :='i';
FileName:=LowerCase(FileName);
Ini:=TIniFile.Create(FileName);
with Ini do
begin
//MainFrom Section
with MainForm do
begin
s:=Name;
SetBounds(ReadInteger(s,csLeft,0),
ReadInteger(s,csTop,0),
ReadInteger(s,csWidth,Width),
ReadInteger(s,csHeight,Height));
WindowState:=TWindowState(ReadInteger(s,csState,integer(WindowState)));
end;
end;
end;
destructor TAppIni.Destroy;
var
i,n:integer;
Ini:TIniFile;
tmpStyles:TFontStyles;
pStyles
ointer;
s:string;
begin
Ini:=TIniFile.Create(FileName);
with Ini do
begin
//MainFrom Section
with MainForm do
begin
s:=Name;
WriteInteger(s,csState,integer(WindowState));
if WindowState<>wsNormal then //如果不为正常的话,
begin
WriteInteger(s,csWidth,540) ; //设为一个常值
WriteInteger(s,csHeight,411);
WriteInteger(s,csLeft,Screen.Height div 2); //各为桌面的一半!
WriteInteger(s,csTop,Screen.Width div 2)
end
else
begin
WriteInteger(s,csWidth,Width);
WriteInteger(s,csHeight,Height);
WriteInteger(s,csLeft,Left);
WriteInteger(s,csTop,Top);
end;
end;
Ini.Free;
end;
end.
‘Acess violation at address 004c4b9e in module 'tian.exe'.read of address FFFFFFFF’
请求大侠帮忙。
unit RegUnit;
interface
uses
IniFiles, SysUtils, Forms, Graphics, Main;
type
TAppIni=class
private
FileName:string;
public
//类成员函数
constructor Create;
destructor Destroy;override;
end;
const
csWidth='Width';
csHeight='Height';
csLeft='Left';
csTop='Top';
csState='State';
csVisible='Visible';
csColor='Color';
csFontName='FontName';
csFontSize='FontSize';
csFontColor='FontColor';
csFontStyle='FontStyle';
csReadOnly='Edit';
csWordWrap='WordWrap';
var
AppIni:TAppIni;
implementation
constructor TAppIni.Create;
var
i,n:integer;
Ini:TIniFile;
pStyles
![Stick Out Tongue :p :p](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f61b.png)
s:string;
begin
//求出应用程序的INI文件名
FileName:=Application.ExeName;
n:=Length(FileName);
FileName[n-2]:='i';
FileName[n-1]:='n';
FileName[n] :='i';
FileName:=LowerCase(FileName);
Ini:=TIniFile.Create(FileName);
with Ini do
begin
//MainFrom Section
with MainForm do
begin
s:=Name;
SetBounds(ReadInteger(s,csLeft,0),
ReadInteger(s,csTop,0),
ReadInteger(s,csWidth,Width),
ReadInteger(s,csHeight,Height));
WindowState:=TWindowState(ReadInteger(s,csState,integer(WindowState)));
end;
end;
end;
destructor TAppIni.Destroy;
var
i,n:integer;
Ini:TIniFile;
tmpStyles:TFontStyles;
pStyles
![Stick Out Tongue :p :p](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f61b.png)
s:string;
begin
Ini:=TIniFile.Create(FileName);
with Ini do
begin
//MainFrom Section
with MainForm do
begin
s:=Name;
WriteInteger(s,csState,integer(WindowState));
if WindowState<>wsNormal then //如果不为正常的话,
begin
WriteInteger(s,csWidth,540) ; //设为一个常值
WriteInteger(s,csHeight,411);
WriteInteger(s,csLeft,Screen.Height div 2); //各为桌面的一半!
WriteInteger(s,csTop,Screen.Width div 2)
end
else
begin
WriteInteger(s,csWidth,Width);
WriteInteger(s,csHeight,Height);
WriteInteger(s,csLeft,Left);
WriteInteger(s,csTop,Top);
end;
end;
Ini.Free;
end;
end.