📄 t_file.pas
字号:
////////////////////////////////////////////////////
// //
// SPR中央宣传部2003年核准下发 中京[2003-6712] //
// SPR Army TMP10Game of China //
// //
// 2003年 //
// 1.0 //
////////////////////////////////////////////////////
//临10局核准下发,13局提供
unit T_File;
interface
uses
Windows, Types,Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, Menus, ComCtrls, StdCtrls, Gauges, ToolWin,inifiles;
procedure GTxtFile_I(filename:string;Strdata:string;li:integer);
function GReadln_ini(im:Timage;filename,data:string;id,li:integer):string;
procedure GWrite_ini(im:Timage;filename,enname,data:string;id,num,li:integer);
//多级写入文件 文件 主键 键名 键数据 分割符号 写入数量---分割符数量
function G_Write_IndexINI(filename,treeBase,NowDate,Treedate:string;feng:char;num:integer):boolean;
//单级读出 文件 主键 键名 读出类型 一般全部为字符
function G_Read_IndexINI(filename,treeBase,NowDate:string;li:integer):string;
//删除键值
procedure G_Delete_IndexINI(filename,Parent:string;indexnum:string;li:integer);
//SPIS格式转道SPISII格式
procedure SpistoSpisII(filename,Newname,CaptionName,DrawName:string);
procedure GDrawtoImage(filename:string;im:Timage;Mrect:TRect;drawli:string);
//删除主键--包括修改顺序号
procedure GdeleteKey(filename,Parent:string;Child:string;li:integer);
//SPR标准格式文件分类
function GFileClass(filename:string):integer;
//SPIS格式文件的读取
procedure GOpen_SpisIIView(im:Timage;filename:string;list:Tlistbox;li:integer;ProgressBar:TProgressBar;Pointlist:Tlistbox);
procedure GOpen_Spis(im:Timage;filename:string;list:Tlistbox;li:integer;ProgressBar:TProgressBar;Pointlist:Tlistbox);
procedure GOpen_SpisIIDraw(im:Timage;filename:string;list:Tlistbox;ProgressBar:TProgressBar;Pointlist:Tlistbox);
Procedure GDraw_spis(im:Timage;filename:string;id,Drawli:integer;ProgressBar:TProgressBar;Pointlist:Tlistbox;li:integer;BoundW,Boundh:integer);
Function GListMemo(filename:string;list:Tlistbox;li:integer):boolean;
Function GListStrings(filename:string;str:Tstrings):boolean;
//文件名转换 省略路径 文件名 转换类型
function G_Filaname(exePath,filename:string;li:integer):string;
//在一定范围(一个矩形)内画SPIS文件
// 画板 文件 画序号 类型 进度条(可为nil) 坐标系输出(可为nil)
Procedure GDraw_spis_(im:Timage;filename:string;id,Drawli:integer;ProgressBar:TProgressBar;Pointlist:Tlistbox;
// 类型 顶坐标 尾坐标
li:integer;BoundTop,BoundBott:TPoint);
implementation
uses T_course;
Procedure GDraw_spis_(im:Timage;filename:string;id,Drawli:integer;ProgressBar:TProgressBar;Pointlist:Tlistbox;
li:integer;BoundTop,BoundBott:TPoint);
var i,M_W,M_H:integer;
str:Ansistring;
begin
case Drawli of
2:begin
M_W:=strtoint(G_Read_IndexINI(filename,inttostr(id),'ImWidth',0));
M_H:=strtoint(G_Read_IndexINI(filename,inttostr(id),'ImHeight',0));
end;
3:begin
M_W:=strtoint(Gshow_title(G_Read_IndexINI(filename,'index','imwh',0),',',3));
M_H:=strtoint(Gshow_title(G_Read_IndexINI(filename,'index','imwh',0),',',4));
end;
end;//case
case li of
1:begin
end;//覆盖绘制
2:begin
for i:=1 to strtoint(G_Read_IndexINI(filename,inttostr(id),'num',0)) do
begin
str:=G_Read_IndexINI(filename,inttostr(id),'ArrayPoint'+inttostr(i),0);
str:=GPointZoomOut(str,
inttostr(im.Width)+','+
inttostr(im.Height)+';'+
inttostr(M_W)+','+
inttostr(M_H)+';',
im,0);
//str:=G_Read_IndexINI(filename,inttostr(id),'ArrayPoint'+inttostr(i),0);
SPIStoCourse(str,im);
GDrawShape_(im,T_Course.DrawingTool,
Gshow_title(Gshow_title(str,':',4),'@',3)
,pmcopy);
if Pointlist <> nil then GgetPointArr(Gshow_title(T_Course.Gshow_title(G_Read_IndexINI(filename,inttostr(id),'ArrayPoint'+inttostr(i),0),':',4),'@',3),Pointlist);
if ProgressBar<> nil then ProgressBar.Position:=i;
end;
end;//缩放绘制
3:begin
for i:=1 to strtoint(G_Read_IndexINI(filename,inttostr(id),'num',0)) do
begin
str:=G_Read_IndexINI(filename,inttostr(id),'ArrayPoint'+inttostr(i),0);
str:=GPointZoomOut(str,
inttostr(abs(Boundtop.x-Boundbott.X))+','+
inttostr(abs(Boundtop.Y-Boundbott.Y))+';'+
inttostr(M_W)+','+
inttostr(M_H)+';',
im,0);
if Boundtop.x < Boundbott.x
then str:=GSpisPoint_str(str,Boundtop.x,1)
else str:=GSpisPoint_str(str,Boundbott.x,1);
if Boundtop.y < Boundbott.y
then str:=GSpisPoint_str(str,Boundtop.y,2)
else str:=GSpisPoint_str(str,Boundbott.y,2);
//str:=G_Read_IndexINI(filename,inttostr(id),'ArrayPoint'+inttostr(i),0);
SPIStoCourse(str,im);
GDrawShape_(im,T_Course.DrawingTool,
Gshow_title(Gshow_title(str,':',4),'@',3)
,pmcopy);
if Pointlist <> nil then GgetPointArr(Gshow_title(T_Course.Gshow_title(G_Read_IndexINI(filename,inttostr(id),'ArrayPoint'+inttostr(i),0),':',4),'@',3),Pointlist);
if ProgressBar<> nil then ProgressBar.Position:=i;
end;
end;//按一定范围缩放
end;//case
end;
Procedure GDraw_spis(im:Timage;filename:string;id,Drawli:integer;ProgressBar:TProgressBar;Pointlist:Tlistbox;li:integer;BoundW,BoundH:integer);
var i,M_W,M_H:integer;
str:Ansistring;
begin
case Drawli of
2:begin
M_W:=strtoint(G_Read_IndexINI(filename,inttostr(id),'ImWidth',0));
M_H:=strtoint(G_Read_IndexINI(filename,inttostr(id),'ImHeight',0));
end;
3:begin
M_W:=strtoint(Gshow_title(G_Read_IndexINI(filename,'index','imwh',0),',',3));
M_H:=strtoint(Gshow_title(G_Read_IndexINI(filename,'index','imwh',0),',',4));
end;
end;//case
case li of
1:begin
if ProgressBar<> nil then ProgressBar.Max:=strtoint(G_Read_IndexINI(filename,inttostr(id),'num',0));
GCreatbmp(im,4,0,M_W,M_H);
for i:=1 to strtoint(G_Read_IndexINI(filename,inttostr(id),'num',0)) do
begin
str:=G_Read_IndexINI(filename,inttostr(id),'ArrayPoint'+inttostr(i),0);
SPIStoCourse(str,im);
GDrawShape_(im,T_Course.DrawingTool,
Gshow_title(Gshow_title(str,':',4),'@',3)
,pmcopy);
if Pointlist <> nil then GgetPointArr(Gshow_title(T_Course.Gshow_title(G_Read_IndexINI(filename,inttostr(id),'ArrayPoint'+inttostr(i),0),':',4),'@',3),Pointlist);
if ProgressBar<> nil then ProgressBar.Position:=i;
end;//for
end;//按原始大小绘制
2:begin
for i:=1 to strtoint(G_Read_IndexINI(filename,inttostr(id),'num',0)) do
begin
str:=G_Read_IndexINI(filename,inttostr(id),'ArrayPoint'+inttostr(i),0);
str:=GPointZoomOut(str,
inttostr(im.Width)+','+
inttostr(im.Height)+';'+
inttostr(M_W)+','+
inttostr(M_H)+';',
im,0);
//str:=G_Read_IndexINI(filename,inttostr(id),'ArrayPoint'+inttostr(i),0);
SPIStoCourse(str,im);
GDrawShape_(im,T_Course.DrawingTool,
Gshow_title(Gshow_title(str,':',4),'@',3)
,pmcopy);
if Pointlist <> nil then GgetPointArr(Gshow_title(T_Course.Gshow_title(G_Read_IndexINI(filename,inttostr(id),'ArrayPoint'+inttostr(i),0),':',4),'@',3),Pointlist);
if ProgressBar<> nil then ProgressBar.Position:=i;
end;
end;//按现有画布缩放
3:begin
for i:=1 to strtoint(G_Read_IndexINI(filename,inttostr(id),'num',0)) do
begin
str:=G_Read_IndexINI(filename,inttostr(id),'ArrayPoint'+inttostr(i),0);
str:=GPointZoomOut(str,
inttostr(BoundW)+','+
inttostr(BoundH)+';'+
inttostr(M_W)+','+
inttostr(M_H)+';',
im,0);
//str:=G_Read_IndexINI(filename,inttostr(id),'ArrayPoint'+inttostr(i),0);
SPIStoCourse(str,im);
GDrawShape_(im,T_Course.DrawingTool,
Gshow_title(Gshow_title(str,':',4),'@',3)
,pmcopy);
if Pointlist <> nil then GgetPointArr(Gshow_title(T_Course.Gshow_title(G_Read_IndexINI(filename,inttostr(id),'ArrayPoint'+inttostr(i),0),':',4),'@',3),Pointlist);
if ProgressBar<> nil then ProgressBar.Position:=i;
end;
end;//按一定范围缩放
end;//case
end;
Function GListStrings(filename:string;str:Tstrings):boolean;
var i:integer;
begin
result:=true;
case GFileClass(filename) of
2:for i:=1 to strtoint(G_Read_IndexINI(filename,'index','num',0)) do
str.Add(G_Read_IndexINI(filename,inttostr(i),'enname',0));
3:for i:=1 to strtoint(G_Read_IndexINI(filename,'index','num',0)) do
str.Add(inttostr(i));
4:for i:=1 to strtoint(G_Read_IndexINI(filename,'index','num',0)) do
str.Add(G_Read_IndexINI(filename,inttostr(i),'name',0));
5:begin
end;
6:begin
end;
7:begin
end;
8:begin
end;
9:begin
end;
else result:=false;
end;//case
end;
Function GListMemo(filename:string;list:Tlistbox;li:integer):boolean;
var i:integer;
begin
result:=true;
case li of
0:list.Items.Clear;
end;//case
case GFileClass(filename) of
2:for i:=1 to strtoint(G_Read_IndexINI(filename,'index','num',0)) do
list.Items.Add(G_Read_IndexINI(filename,inttostr(i),'enname',0));
3:for i:=1 to strtoint(G_Read_IndexINI(filename,'index','num',0)) do
list.Items.Add(inttostr(i));
4:for i:=1 to strtoint(G_Read_IndexINI(filename,'index','num',0)) do
list.Items.Add(G_Read_IndexINI(filename,inttostr(i),'name',0));
5:begin
end;
6:begin
end;
7:begin
end;
8:begin
end;
9:begin
end;
else result:=false;
end;//case
end;
function G_Read_IndexINI(filename,treeBase,NowDate:string;li:integer):string;
var
MyIniFile: TIniFile;
begin
MyIniFile := TIniFile.Create(filename);
case li of
0:result:=MyIniFile.Readstring(treebase,nowdate, '');
1:result:=inttostr(MyIniFile.Readinteger(treebase,nowdate, 0));
2:if MyIniFile.Readbool(treebase,nowdate, false)
then result:='true'
else result:='false';
end;
MyIniFile.Free;
end;
function G_Write_IndexINI(filename,treeBase,NowDate,Treedate:string;feng:char;num:integer):boolean;
var
MyIniFile: TIniFile;
str:string;
i:integer;
begin
try
MyIniFile := TIniFile.Create(filename);
for i:=1 to num do begin
str:=T_course.Gshow_title(NowDate,feng,3);
MyIniFile.writestring(treeBase, str, T_course.Gshow_title(Treedate,feng,3));
NowDate:=T_course.Gshow_title(NowDate,feng,4);
Treedate:=T_course.Gshow_title(Treedate,feng,4);
end;
MyIniFile.Free;
result:=true;
except result:=false; end;
end;
function GReadln_ini(im:Timage;filename,data:string;id,li:integer):string;
var
MyIniFile: TIniFile;
str:ansistring;
i:integer;
begin
//MyIniFile := TIniFile.Create(ExtractFilePath(Application.Exename)+'');
MyIniFile := TIniFile.Create(filename);
str:=inttostr(id);
case li of
1:begin
MyIniFile.Readinteger(str, 'ImWidth', 0);
MyIniFile.Readinteger(str, 'ImHeight', 0);
for i:=1 to MyIniFile.Readinteger(str, 'num', 1) do
MyIniFile.ReadString(str, 'ArrayPoint'+inttostr(i), '')
end;
2:begin
result:=MyIniFile.ReadString(str, data, '');
end;
end;//case
MyIniFile.Free;
end;
procedure GWrite_ini(im:Timage;filename,enname,data:string;id,num,li:integer);
var
MyIniFile: TIniFile;
str:string;
begin
//MyIniFile := TIniFile.Create(ExtractFilePath(Application.Exename)+'');
MyIniFile := TIniFile.Create(filename);
str:=inttostr(id);
case li of
1:begin
MyIniFile.Writeinteger(str, 'ImWidth', im.Width);
MyIniFile.Writeinteger(str, 'ImHeight', im.Height);
MyIniFile.Writestring(str,'enname',enname);
MyIniFile.Writeinteger(str, 'num', num);
MyIniFile.WriteString(str, 'ArrayPoint'+inttostr(num), data);
end;
2:begin
MyIniFile.DeleteKey(enname,'ImWidth');
MyIniFile.DeleteKey(enname,'ImHeight');
MyIniFile.DeleteKey(enname,'enname');
MyIniFile.DeleteKey(enname,'num');
MyIniFile.DeleteKey(enname,'ArrayPoint'+inttostr(num));
end;
3:begin
end;
end;//case
MyIniFile.Free;
end;
//文件名、父亲名、删除内容,类型号
procedure GdeleteKey(filename,Parent,Child:string;li:integer);
var MyIniFile: TIniFile;
begin
case li of
1:begin
MyIniFile := TIniFile.Create(filename);
MyIniFile.DeleteKey(Parent,Child);
MyIniFile.Free;
end;
end;
end;
//文件名、父亲名、排列索引号,一般为Num、类型号
procedure G_Delete_indexini(filename,Parent:string;indexnum:string;li:integer);
var str:string;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -