Jump to content
Kurt G

Newbee: FMX: Can't find DirectoryListBox or FileListBox

Recommended Posts

I an totally new to RAD, and have installed RAD 11.2.

I want to convert a project from Delphi5 to RAD 11.2 in Multi-Device App. as it can rotate an Image.

I therefor started a new app. but I can not find anything like ListBox or FileListBox.

Is there no procedure or function in RAD 11.2 to do the job?

Is there another way i FMX to do it?

 

Share this post


Link to post
3 hours ago, Kurt G said:

convert a project from Delphi5 to RAD 11.2 in Multi-Device App.

Best to leave that D5 code behind. FMX code can be earned by running the example samples for FMX.  The FMX code has an OpenDialog component that might give you start.

 

 

Share this post


Link to post

I have given up the D5 code.

I started from beginning by selecting Multi-Device Application.

But I still nead the function to list directory and files, and I have not found any examples for that until now.

Share this post


Link to post

FMX does have TListView.   

procedure TForm9.Button1Click(Sender: TObject);
var
  Lvi : TListViewItem;
  I : Integer;
  DirArray : TStringDynArray;
begin
  Lvi := ListView1.Items.Add;
  Lvi.Text := 'Hello';
  Lvi := ListView1.Items.Add;
  Lvi.Text := 'FMX';
  Lvi := ListView1.Items.Add;

  Lvi.Text := Tdirectory.GetCurrentDirectory;
  DirArray := TDirectory.GetFiles(Lvi.Text);
  var Filename: string;
  for I := 0 to High(DirArray) do
  begin
    Filename := DirArray[I];
    Lvi := ListView1.Items.Add;
    Lvi.Text := fileName;
  end;
end;

 

Share this post


Link to post

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.Controls.Presentation, FMX.StdCtrls, FMX.Layouts,
  System.IOUtils,
  FMX.ListBox;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.Button1Click(Sender: TObject);
var
  Lvi : TListViewItem;
  I : Integer;
  DirArray : TStringDynArray;
begin
  Lvi := ListView1.Items.Add;
  Lvi.Text := 'Hello';
  Lvi := ListView1.Items.Add;
  Lvi.Text := 'FMX';
  Lvi := ListView1.Items.Add;

  Lvi.Text := Tdirectory.GetCurrentDirectory;
  DirArray := TDirectory.GetFiles(Lvi.Text);
  var Filename: string;
  for I := 0 to High(DirArray) do
  begin
    Filename := DirArray;
    Lvi := ListView1.Items.Add;
    Lvi.Text := fileName;
  end;
end;

end.

-----------------------------------------------------

 

A lot has happened since D5! 🙂

I started a new project and placed a Tbutton and a TListBox on the form.

But the compiler give error: Undeclared identifier: TListviewItem in the line:   Lvi : TListViewItem;

 

See the code in Unit.pas.

 

 

Unit1.pas

Share this post


Link to post
On 9/25/2022 at 1:28 PM, Pat Foley said:

FMX does have TListView. 

So discard old ListBox and use TListView component.  

Also add a memo1 and this 

procedure TForm9.ListView1Change(Sender: TObject);
var
  fn: string;
begin
  fn := Listview1.items[ListView1.ItemIndex].Text;
  if Pos('.txt',Fn) > 0 then
     memo1.Lines.LoadFromFile(fn);
end;

Share this post


Link to post
16 hours ago, Kurt G said:

But the compiler give error: Undeclared identifier: TListviewItem in the line:   Lvi : TListViewItem;

You declare a TListbox not a TListView  so it's normal, units for Tlistview ( FMX.TlistView,FMX.TlistView.xxxx)  are not declared
works with a TlistView

image.thumb.png.0b21752a820b9aaa732b23f20e4acbd7.png


A list box (simple one without style) should be filled with Listbox1.Items.Add('Hello')
image.thumb.png.af4d5ce47078989151d43062a5ee8ed4.png

 

other way is to declare a TListboxItem

var aItem : TlistboxItem;
begin
  aItem:=TlistboxItem.Create(Self);
  aItem.Parent:=ListBox1;
  aItem.Text:='Hello';
end;

P.S. If you want to involve style, here is a tutorial I wrote (long time ago, XE4, when TListview does not exists) Intro to styles Firemonkey XE4 (sorry in French)
 

 

 

Edited by Serge_G

Share this post


Link to post
Thanks for your help, it's starting to come through.
I am having problems with the components disappearing from the Frame.
I must have found a tutorial about the IDE, but it shouldn't be YOU TUBE, I prefer to read.

Share this post


Link to post

 

Serge_G listbox coding is very nice example.  Serge's "Introduction to FireMonkey XE4 Styles" is good start about differences between FMX and VCL and in text!  His A.F.R.O may help you with the disappearing.  

 

Here's a one liner that brings up the opendialog and returns the directory or folder selected. 

   if not SelectDirectory('Dirs, Folders','', FilePath) then exit;
    DirArray := TDirectory.GetFiles(FilePath,'*.*',TSearchOption.soTopDirectoryOnly);
    ...

 

Share this post


Link to post
35 minutes ago, Pat Foley said:

Serge_G listbox coding is very nice example.  Serge's "Introduction to FireMonkey XE4 Styles" is good start about differences between FMX and VCL and in text!  His A.F.R.O may help you with the disappearing.  

Thanks, but this AFRO thing is now obsolete because IDE force it when you close designer (ouf)

Share this post


Link to post
20 minutes ago, Serge_G said:

because IDE force it when you close designer

What happens in Multi-Device Preview when design window closed?   Another goodie is the form screen position shows the wallpaper in color, albeit only follows left and Top and not property position setting.  

Share this post


Link to post

I don't know what "AFRO" and "(ouf)" in "Thanks, but this AFRO thing is now obsolete because IDE force it when you close designer (ouf)"  mean. Can anyone help?

Share this post


Link to post

TListBox is there in FMX. I'm not sure why you think it's not.

 

Regarding rotating images. You may know this already but the best way to do it is by setting the Matrix property of the TCanvas you're drawing to. Use TMatrix.CreateRotation to create the matrix from a rotation angle. The advantage of this method is that the GPU takes care of all the transformations. It's also easy to combine with other transformations such as scaling or translation. TBitmap.Rotate is essentially doing that for you, but gives you less control.

Edited by XylemFlow

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×