Trouble with TFileOpen standard action lazarus / 31-LCL ---------------------------------------------------------------------- simsee · 2016-10-02 15:22 I'm new with Lazarus and I'm trying to understand actions (with some difficulties...). I have ActionList1 : TactionList with a standard action FileOpen1 : TFileOpen. Moreover I have Button1 : TButton on the main form, with its action property set to FileOpen1 : TFileOpen. In order to show the filename selected by the user in the dialog, I use the OnAccept event of the action, with the following code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FileOpen1Accept(Sender: TObject);beginShowMessage(FileOpen1.FileName);end; but I have an error by the compiler (identifier idents no member "filename"). Since FileOpen1 object is an instance of class TFileOpen, that inherits the property FileName from TFileAction, why I can't use this property? And how can I know the filename selected in the dialog? Thanks id advance. ---------------------------------------------------------------------- wp · 2016-10-02 15:52 Look carefully at the object inspector: Filename is not a direct property of the TFileOpen action, but of its Dialog property. Therefore, you must call Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FileOpen1Accept(Sender: TObject);begin  ShowMessage(FileOpen1.Dialog.FileName);end; If you want to learn about Actions read Brian Long's article http://www.blong.com/Conferences/BorCon2003/Actions/6102.htm. It is about Delphi's actions, but everything can be applied to Lazarus as well. ---------------------------------------------------------------------- simsee · 2016-10-02 16:17 Thank you. Now my demo works. I missed this important detail. I have read a more recert article by B. Long about actions on Delphi XE3, but there are some differences with Lazarus... ---------------------------------------------------------------------- wp · 2016-10-02 16:20 Yes, that's why I referred to the older article. The newer article also mentions TActionManager and TActionBars which are not available in Lazarus. ---------------------------------------------------------------------- simsee · 2016-10-02 17:09 A final doubt: TFileOpen also inherits 'filename' protected property from TFileAction. So, why I can't write also: fileopen1.filename? I apologize for insisting with my trivial question... (see: http://lazarus- ccr.sourceforge.net/docs/lcl/stdactns/tfileopen.html http://lazarus-ccr.sourceforge.net/docs/lcl/stdactns/tfileaction.html) ---------------------------------------------------------------------- wp · 2016-10-02 17:38 But TFileAction's "FileName" is protected, and TFileOpen does not change its visibility, i.e. TFileOpen.FileName is still protected. You can access protected properties only from ancestors of the class which introduced them, but not from outside. An often-found trick is to inherit from the class with the protected property and to re-declare the property as public. Then a type-cast to the new class will give you access to the initially protected property: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TMyFileOpen = class(TFileOpen)  public    property FileName;  end; procedure TForm1.FileOpen1Accept(Sender: TObject);begin  ShowMessage(TMyfileOpen(FileOpen1).FileName);end; Certainly this is some kind of hack because the programmer must have had something in mind when the property was declared only as protected. ---------------------------------------------------------------------- simsee · 2016-10-02 18:17 Now I understand. Your answer is very clear! Thanks again!