Advertisement
TLama

Untitled

Sep 3rd, 2014
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.84 KB | None | 0 0
  1. function TryGetFileLine(const FileName: string; Index: Integer; out Line: string): Boolean;
  2. var  
  3.   FileLines: TArrayOfString;
  4. begin
  5.   // the function succeed when the file can be loaded and the count of lines is
  6.   // greater than the requested line index (it is 0 based index, hence the line
  7.   // count must be greater)
  8.   Result := LoadStringsFromFile(FileName, FileLines) and (GetArrayLength(FileLines) > Index);
  9.   // if the above succeeded, return the file line of the requested index to the
  10.   // output parameter
  11.   if Result then
  12.     Line := FileLines[Index];
  13. end;
  14.  
  15. function GetFirstFileLine(const FileName, Default: string): string;
  16. begin
  17.   if not TryGetFileLine(FileName, 0, Result) then
  18.     Result := Default;
  19. end;
  20.  
  21. ...
  22. procedure DirEditChange(Sender: TObject);
  23. begin
  24.   ...
  25.   L2Ver2.Caption := GetFirstFileLine(FilePath, 'N/A');
  26. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement