как сделать, чтобы дельфи открывал файл, менял кодировку на свою, выполнял код и потом менял обратно? заранее спасибо
type
TPerson = record
Surname: string[24];
данные1: string[14];
данные2: string[10];
данные3: string[21];
size: string[13];
skotor: string[10];
pokotor: String[10];
zakotor: string[10];
primech: string[10];
end;
TArrPerson = array [0..0] of TPerson;
PPersons = ^TArrPerson;
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
OpenDialog: TOpenDialog;
SaveDialog: TSaveDialog;
StatusBar1: TStatusBar;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function ReplaceChar(Value: string; cfrom,cto:char): string;
var tmp:string;
begin
tmp:=Value;
while pos(cfrom,tmp)>0 do
tmp[pos(cfrom,tmp)]:=cto;
result:=tmp;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog.Execute then
Edit1.Text:=OpenDialog.FileName;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if OpenDialog.Execute then
Edit2.Text:=OpenDialog.FileName;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if SaveDialog.Execute then
Edit3.Text:=SaveDialog.FileName;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
Persons: PPersons;
i, j, count, MyF : integer;
search:boolean;
f,fout: textfile;
tmp: string;
tmp2: Pansichar;
//Persons: Fpersons;
tmp1: string[14];
Formats, fs: TFormatSettings;
begin
Formats.LongDateFormat:='DD/MM/YYYY';
Formats.ShortDateFormat:='DD/MM/YYYY';
tmp2:='�¥â ¤***ëå';
// AnsiToOem(tmp2,tmp2);
// CharToOem(tmp2,tmp2);
count:=0;
AssignFile(f,Edit1.Text);
ReSet(f);
Readln(f,tmp);
Readln(f,tmp);
Readln(f,tmp);
Readln(f,tmp);
Readln(f,tmp);
Readln(f,tmp);
Readln(f,tmp);
Readln(f,tmp);
Readln(f,tmp);
// Readln(f,tmp);
// Readln(f,tmp);
while copy(tmp,3,5) <>'-----' do
begin
ReAllocMem(Persons, SizeOf(TPerson)*(count+1));
//ShowMessage(tmp);
Persons^[count].SNILS:=trim(copy(tmp,10,14));
// ShowMessage(tmp);
Persons^[count].Surname:=trim(copy(tmp,25,23));
Persons^[count].данные1:=trim(copy(tmp,50,10));
Persons^[count].данные2:=trim(copy(tmp,61,22));
Persons^[count].данные3:=trim(copy(tmp,84,13));
if length(trim(copy(tmp,98,10)))>0 then
Persons^[count].skotor:=trim(copy(tmp,98,10))
else Persons^[count].skotor:=' ';
if length(trim(copy(tmp,109,10)))>0 then
Persons^[count].pokotor:=trim(copy(tmp,109,10))
else Persons^[count].pokotor:=' ';
if length(trim(copy(tmp,120,10)))>0 then
Persons^[count].zakotor:=trim(copy(tmp,120,10))
else Persons^[count].zakotor:=' ';
Persons^[count].primech:=trim(copy(tmp,131,10));
inc(count);
Readln(f,tmp);
end;
// ShowMessage(IntToStr(count));
ReAllocMem(Persons, SizeOf(TPerson)*(count+0));
CloseFile(f);
AssignFile(f,Edit2.Text);
// tmp1:=tmp;
// While length(tmp1)<30 do
ReSet(f);
AssignFile(fout,Edit3.Text);
ReWrite(fout);
readln(f,tmp);
writeln(fout,tmp);
i:=0;
while not eof(f) do
begin
Search:=False;
MyF:=0;
for j:=1 to 7 do
begin
Readln(F,tmp);
Writeln(Fout,tmp);
end;
readln(f,tmp);
tmp1:=copy(tmp,10,14);
//ShowMessage(tmp1);
writeln(fout,tmp);
for j:=1 to 12 do
begin
readln(f,tmp);
writeln(fout,tmp);
end;
//Writeln(fout,tmp);
for j:=0 to count-1 do
begin
if pos(Persons^[j].SNILS,tmp1)>0 then
begin
Search:=true;
MyF:=j;
end;
end;
if not Search then
writeln(fout,tmp2)
else
begin
tmp:=Persons^[MyF].данные1+' '+Persons^[MyF].Surname+' '+Persons^[MyF].данные2+Persons^[MyF].данные3+' '+Persons^[MyF].size+' '+Persons^[MyF].skotor+' '+Persons^[MyF].pokotor+' '+Persons^[MyF].zakotor+' '+Persons^[MyF].primech;
writeln(fout,tmp);
end;
readln(f,tmp);
readln(f,tmp);
writeln(fout,tmp);
inc(i);
StatusBar1.Panels[0].Text:='Îáðàáîòàíî: '+inttostr(i);
Application.ProcessMessages;
end;
ShowMessage('Ãîòîâî');
end;
end.