function Read_ini(junk:string):boolean;
var
folderName : string;
fileName : string;
myFile : TextFile;
data : string;
begin
//showmessage (Board.FileName);
//showmessage (PCBServer.GetCurrentPCBBoard.FileName);
//showmessage (ExtractFilePath(Application.ExeName));
//showmessage (ClientAPI_SpecialFolder_AltiumApplicationData);
// For ini file Saved in Project Folder
FileName := (ExtractFilePath(Board.FileName))+ 'Designators.ini';
// Global ini file
if Not FileExists(FileName) then
begin
// Try to open a text file for writing to
folderName := ExtractFilePath(ClientAPI_SpecialFolder_AltiumApplicationData) + 'Scripts\';
CreateDir (folderName);
FileName := folderName + 'Designators.ini';
end;
//showmessage (FileName);
if FileExists(fileName) then
begin
AssignFile(myFile, fileName);
// Reopen the file in read mode
Reset(myFile);
// Read the file contents
//while not Eof(myFile) do
//begin
//ShowMessage(data);
if not Eof(myFile) then ReadLn(myFile, data);
EditMinHeight.Text:= data;
if not Eof(myFile) then ReadLn(myFile, data);
EditMaxHeight.Text:= data;
if not Eof(myFile) then ReadLn(myFile, data);
EditCommentsTop.Text:= data;
if not Eof(myFile) then ReadLn(myFile, data);
EditCommentsBot.Text:= data;
if not Eof(myFile) then ReadLn(myFile, data);
EditTestPointsTop.Text:= data;
if not Eof(myFile) then ReadLn(myFile, data);
EditTestPointsBot.Text:= data;
//end;
CloseFile(myFile);
result := True
end;
// Debug Code
// Now see if the file exists
// if FileExists(fileName)
// then ShowMessage(fileName+' exists OK')
// else ShowMessage(fileName+' does not exist');
// Delete the file and look again
// DeleteFile(fileName);
// if FileExists(fileName)
// then ShowMessage(fileName+' still exists!')
// else ShowMessage(fileName+' no longer exists');
end;
function Write_ini(junk:string):boolean;
var
folderName : string;
fileName : string;
myFile : TextFile;
begin
// Open a text file for writing to
// For .ini files Saved in Project Folder
fileName := (ExtractFilePath(Board.FileName)) + 'Designators.ini';
AssignFile(myFile, fileName);
ReWrite(myFile);
Write(myFile, EditMinHeight.Text + #13#10);
Write(myFile, EditMaxHeight.Text + #13#10);
Write(myFile, EditCommentsTop.Text + #13#10);
Write(myFile, EditCommentsBot.Text + #13#10);
Write(myFile, EditTestPointsTop.Text + #13#10);
Write(myFile, EditTestPointsBot.Text + #13#10);
CloseFile(myFile);
// Global ini file
if Not FileExists(fileName) then
begin
folderName := ExtractFilePath(ClientAPI_SpecialFolder_AltiumApplicationData) + 'Scripts\';
CreateDir (folderName);
fileName := folderName + 'Designators.ini';
AssignFile(myFile, fileName);
//DeleteFile(fileName);
ReWrite(myFile);
Write(myFile, EditMinHeight.Text + #13#10);
Write(myFile, EditMaxHeight.Text + #13#10);
Write(myFile, EditCommentsTop.Text + #13#10);
Write(myFile, EditCommentsBot.Text + #13#10);
Write(myFile, EditTestPointsTop.Text + #13#10);
Write(myFile, EditTestPointsBot.Text + #13#10);
CloseFile(myFile);
end;
end;
Debug Code
// See if the file exists
// if FileExists(fileName)
// then ShowMessage(fileName+' exists OK')
// else ShowMessage(fileName+' does not exist');
// Delete the file and look again
// DeleteFile(fileName);
// if FileExists(fileName)
// then ShowMessage(fileName+' still exists!')
// else ShowMessage(fileName+' no longer exists');
Related Links:
Delphi Basics : Files
Showing posts with label Delphi. Show all posts
Showing posts with label Delphi. Show all posts
Sunday, May 28, 2017
Saturday, October 19, 2013
Delphi Files, Directories, Disks, I/O
efg's Delphi Reference Library
Delphi Resources and Technical Topics
Trigonometric Functions
'via Blog this'
Delphi Resources and Technical Topics
Trigonometric Functions
'via Blog this'
Wednesday, October 16, 2013
Measuring code performance in Delphi Scripts
First step in code optimization is to determine which procedures in our code need to be optimized.
A millisecond timer is needed to test for the elapsed time required to execute the code.
On a Windows Machine we can use 'GetTickCount'. Below is a code snippet for Delphi.
procedure TForm1.ButtonClick(Sender: TObject);
var
startTick : DWord;
delta : DWord;
begin
startTick := GetTickCount;
DoSomething; // Your Code
delta := GetTickCount - startTick;
ShowMessage(IntToStr(delta) + 'ms');
end;
See what CapnBry has to say about GetTickCount:
'via Blog this'
A millisecond timer is needed to test for the elapsed time required to execute the code.
On a Windows Machine we can use 'GetTickCount'. Below is a code snippet for Delphi.
procedure TForm1.ButtonClick(Sender: TObject);
var
startTick : DWord;
delta : DWord;
begin
startTick := GetTickCount;
DoSomething; // Your Code
delta := GetTickCount - startTick;
ShowMessage(IntToStr(delta) + 'ms');
end;
See what CapnBry has to say about GetTickCount:
'via Blog this'
Subscribe to:
Posts (Atom)