Search code examples
delphidelphi-7

trying to find file location, I got this error (Error Record, object or class type required)


I was trying to get file location (D:\Documents\Work) on edit components with this code

procedure TForm3.btn1Click(Sender: TObject);
begin
  if dlgOpen1.Execute then
    if FileExists(dlgOpen1.FileName) then
      edt5.Text.ExtractFileDir(dlgOpen1.FileName)
    else
      raise Exception.Create('File does not exist.');
end;

Solution

  • edt5.Text.ExtractFileDir(dlgOpen1.FileName) is not valid. edt5 appears to be a TEdit, and TEdit controls don't have a Text.ExtractFileDir method.

    Your code should read

    edt5.Text := ExtractFileDir(dlgOpen1.FileName);