Category: StackOverflow

How clone TChart in FMX

How do i clone a TChart at runtime? I found this link but it is Delphi and i can't translate to C++ Builder. Here is what i tried but i get an error at runtime of Class TChart not found: TChart *tmp = new TChart(Chart1->Clone(this)); tmp->Parent = this->Panel2; Also, how can i clone so that i can easily reference the new clones in code - e.g. Chart(2), Chart(3) etc.
Read More

How to use Image1.Bitmap.BitmapChanged;

Bitmap.BitmapChanged; is protected in FMX.Graphics so I cannot use the procedure. Useing a TImage or TImageControler I am drawing a line but the line does not show. I am using this snippet: imgc1.Bitmap.Canvas.BeginScene; imgc1.Bitmap.Canvas.DrawLine(FStartPoint,FEndPoint, 100); imgc1.Bitmap.Canvas.EndScene; imgc1.Bitmap.BitmapChanged; // the original example said that this would redraw the image. In my CE Rio IDE the BitmapChanged is undefind. How can I use it? Draw the line. IDE cannot find BitmapChanged.
Read More

convert vcl project to fmx Delphi 10.3

I try to use Listview in my fmx project , and grab text from it Like vcl , How can I using it in fmx project not in vcl ? procedure TForm1.Button1Click(Sender: TObject); var item: TListItem; begin item := ListView1.Items.Add; item.Caption := 'Mohamed'; item.SubItems.Add('Akram'); item.SubItems.Add('055002011'); item.ImageIndex := 0; end; procedure TForm1.CaptionclickClick(Sender: TObject); begin Memo1.Lines.Add('caption : ' + ListView1.Items[ListView1.Selected. Index].Caption); end; procedure TForm1.FirstitemclickClick(Sender: TObject); begin Memo1.Lines.Add('First sub item : ' + ListView1.Items[ListView1.Selected. Index].SubItems[0]); end; procedure TForm1.SeconditemclickClick(Sender: TObject); begin Memo1.Lines.Add('Second sub item : ' + ListView1.Items[ListView1.Selected. Index].SubItems[1]); end; https://6.top4top.net/p_1260py56w1.jpg
Read More

How to bring a TreeViewItem in the visible (scroll) area

I'm looking for a way to navigate by code to an item in a tree view. The object should be moved into the visible area. I could not find a method in either TTreeView or TTreeViewItem. The following approach does not work under all circumstances because the item position is not always updated: procedure TfmxMain.MakeItemVisible(Item: TTreeViewItem); begin trvMyTreeView.ViewportPosition := TPointF.Create(min(Item.Position.X - trvSlideGroups.ClientWidth / 2, 0), min(Item.Position.Y - trvSlideGroups.ClientHeight / 2, 0)); end;
Read More

How to refresh TListView LiveBinding with TAdapterBindSource

I am using Delphi 10.3.1 (Firemonkey FMX) to build android and iOS app. I have a TListView, live binding with a AdapterBindSource. My problem is: new records does not appear after Adapter refreshed. ============== I created a TObjectList, added 3 objects to it I created a TBindSourceAdapter by passing a TObjectList to create it. I assign the TBindSourceAdapter to AdapterBindSource1.Adapter. Then I Free the TObjectList and re-create it, add 4 newly created objects (3 of them are old records, with some data modified, 1 is a new record) I do TBindSourceAdapter.Refresh and TAdapterBindSource.Refresh Those 3 old records are refreshed successfully with modified data displayed, but the new record is not showing up in Android and iOS The same logic working fine in Windows platform ============== My logic create TObjectList first I get records from Rest Server and converted into a TObjectList TData : class(TObject) ... // a class stored some data TDataList = class(TObjectList<TData>) // then I get data from Rest Server and created FList, it is a Form private variable FList := TDataList.Create; // a private Form variable // create Tdata objects and add to FList ..... create TBindSourceAdapter, assign to AdapterBindSource var ABindSourceAdapter: TBindSourceAdapter; // .... ABindSourceAdapter := TListBindSourceAdapter<TData>.Create(self, FList, True); AdapterBindSource1.Adapter := ABindSourceAdapter; AdapterBindSource1.Active := true; then the records show on ListView which live bindings with the AdapterBindSource Refresh FList records When click on Refresh button, I trigger to get data from Rest server again, I do free the FList and re-create it FreeAndNil(FList); FList := TDataList.Create; // re-create the list, then create Tdata object and add to it again. refresh the Adapter then I refresh the adapter AdapterBindSource1.Adapter.Refresh; AdapterBindSource1.Refresh; here the 3 old records are refreshed successfully, modified data are displayed correctly, however, new record is not showing, the TListView still showing 3 records only. Notes: I did not re-create TListBindSourceAdapter and assign to AdapterBindSource1.Adapter again during refresh, the records still refreshed successfully. However, even I re-create TListBindSourceAdapter and assign to AdapterBindSource1.Adapter again, new record still does not show up, only caused memory leaking. How can I resolve this? is there something I missing like to refresh the TListView? Or my BindSourceAdapter refresh logic is wrong? Thanks for any help.
Read More

How to stop duplicating child components (Delphi 10.1 Berlin Firemonkey)

I am creating a component with a published "VisibleItems" property. When the property of an item is checked/un-checked an item is either added or removed from the component and stored in the dfm (Which works), however; when the the component is streamed from the dfm into the IDE duplicate items are created. I've overridden the protected "Loaded" procedure of the item (TMyTreeViewItem) and added a "CreateDefaultItem" procedure to the parent component (TDesignTimeTreeView) which appears to work for Windows but not for Android. I tried marking properties in the parent and child components with the "stored False" directive. I've also tried overriding the "Loaded" procedure in the main component. Below is a minimal version of the component. If the TMyTreeViewItem.Loaded and TDesignTimeTreeView.CreateDefaultItem are bypassed the component duplication starts to happen in the IDE when toggling between "View as Text" and "View as Form" (Alt + F12). unit DesignTimeTreeView; interface uses System.SysUtils, System.Classes, System.Types, System.UITypes, FMX.Types, FMX.Controls, FMX.Layouts, FMX.TreeView; type {$SCOPEDENUMS ON} TItemId = (NONE, Default, Custom, One, Two); {$SCOPEDENUMS OFF} TMyTreeViewItem = class(TTreeViewItem) private FId : TItemId; procedure SetFId(const Value: TItemId); protected procedure Loaded; override; published property Id: TItemId read FId write SetFid; end; TVisibleItemsChange = procedure(Id: TItemId; Visible: Boolean) of object; TVisibleItems = class(TPersistent) private FItem1 : Boolean; FItem2 : Boolean; FOnChange : TVisibleItemsChange; procedure SetVisibility(Id: TItemId; Visible: Boolean); procedure SetFItem1(const Visible: Boolean); procedure SetFItem2(const Visible: Boolean); property OnChange: TVisibleItemsChange read FOnChange write FOnChange; published property Item1: Boolean read FItem1 write SetFItem1; property Item2: Boolean read FItem2 write SetFItem2; end; TDesignTimeTreeView = class(TTreeView) private { Private declarations } FVisibleItems : TVisibleItems; FDefaultMyTreeViewItem : TMyTreeViewItem; function GetItemById(Id: TItemId): TMyTreeViewItem; function GetItemName(Id: TItemId): string; procedure AddItem(Id: TItemId); procedure OnVisibilityChange(Id: TItemId; Visible: Boolean); procedure OnItemClick(Sender: TObject); procedure OnItemTap(Sender: TObject; const Point: TPointF); procedure CreateDefaultItem; const PREFIX = 'StandardItem_'; protected { Protected declarations } public { Public declarations } constructor Create(AOwner: TComponent); override; published { Published declarations } property VisibleItems: TVisibleItems read FVisibleItems write FVisibleItems; end; procedure Register; implementation procedure Register; begin RegisterComponents('Samples', [TMyTreeViewItem, TDesignTimeTreeView]); end; { TDesignTimeTreeView } procedure TDesignTimeTreeView.AddItem(Id: TItemId); var Item : TMyTreeViewItem; ItemName : string; i : Integer; Sub : TTreeViewItem; begin ItemName := GetItemName(Id); Item := GetItemById(Id); if Item <> nil then RemoveObject(Item); Item := TMyTreeViewItem.Create(nil); Item.FId := Id; Item.Text := ItemName; Item.Name := ItemName; Item.HitTest := True; Item.OnClick := OnItemClick; Item.OnTap := OnItemTap; Item.Parent := Self; for i := 1 to 10 do begin Sub := TTreeViewItem.Create(nil); Sub.Text := 'Sub Item (' + i.ToString + ')'; Sub.Parent := Item; end; end; constructor TDesignTimeTreeView.Create(AOwner: TComponent); begin inherited Create(AOwner); ItemHeight := 46; CreateDefaultItem; FVisibleItems := TVisibleItems.Create; FVisibleItems.OnChange := OnVisibilityChange; { Set the default values } FVisibleItems.FItem1 := False; FVisibleItems.FItem2 := False; end; procedure TDesignTimeTreeView.CreateDefaultItem; var Item : TMyTreeViewItem; const DEFAULT_ITEM_NAME = 'DEFAULT_MYTREEVIEWITEM'; begin if Owner <> nil then if Owner.FindComponent(DEFAULT_ITEM_NAME) <> nil then begin Item := TMyTreeViewItem(Owner.FindComponent(DEFAULT_ITEM_NAME)); if Item.Id <> TItemId.Default then Item.Free else Exit; end; if Assigned(FDefaultMyTreeViewItem) then FreeAndNil(FDefaultMyTreeViewItem); FDefaultMyTreeViewItem := TMyTreeViewItem.Create(Owner); FDefaultMyTreeViewItem.FId := TItemId.Default; FDefaultMyTreeViewItem.Name := DEFAULT_ITEM_NAME; FDefaultMyTreeViewItem.Text := 'Created by TDesignTimeTreeView. This makes it so you do not have ' + 'to add a TMyTreeViewItem on the form just so this component will ' + 'work.'; FDefaultMyTreeViewItem.Parent := TFmxObject(Owner); FDefaultMyTreeViewItem.Visible := False; end; function TDesignTimeTreeView.GetItemById(Id: TItemId): TMyTreeViewItem; var i : Integer; ItemName : string; begin Result := nil; ItemName := GetItemName(Id); for i := 0 to Count - 1 do if Items[i].Name = ItemName then Result := TMyTreeViewItem(Items[i]); end; function TDesignTimeTreeView.GetItemName(Id: TItemId): string; begin Result := PREFIX + Ord(Id).ToString; end; procedure TDesignTimeTreeView.OnItemClick(Sender: TObject); var Item : TMyTreeViewItem; begin Item := TMyTreeViewItem(Sender); Item.Text := Ord(Item.Id).ToString + ' Clicked (' + FormatDateTime('h:nn:ss.zzzAM/PM', Now) + ')'; end; procedure TDesignTimeTreeView.OnItemTap(Sender: TObject; const Point: TPointF); begin OnItemClick(Sender); end; procedure TDesignTimeTreeView.OnVisibilityChange(Id: TItemId; Visible: Boolean); var Item : TMyTreeViewItem; begin Item := GetItemById(Id); if Item <> nil then RemoveObject(Item); if Visible then AddItem(Id); end; { TVisibleItems } procedure TVisibleItems.SetFItem1(const Visible: Boolean); begin SetVisibility(TItemId.One, Visible); end; procedure TVisibleItems.SetFItem2(const Visible: Boolean); begin SetVisibility(TItemId.Two, Visible); end; procedure TVisibleItems.SetVisibility(Id: TItemId; Visible: Boolean); begin case Id of TItemId.Custom: { Do Nothing }; TItemId.One: FItem1 := Visible; TItemId.Two: FItem2 := Visible; end; if Assigned(FOnChange) then FOnChange(Id, Visible); end; { TMyTreeViewItem } procedure TMyTreeViewItem.Loaded; begin if Id = TItemId.NONE then begin Self.Destroy; Exit; end; if Id = TItemId.Default then Exit; if not (Parent is TDesignTimeTreeView) then Self.Destroy; inherited; end; procedure TMyTreeViewItem.SetFId(const Value: TItemId); begin { Read Only: But we want to see it in the .fmx file of the form } end; end. I expect that when VisibleItems.Item1 is checked a TMyTreeViewItem will be added to the component and stored in the dfm (Which is working). The component also appears to be streaming from the dfm to the IDE correctly. I also expect to see Item1 and Item2 on the form (If they are checked) when the program runs (Which is working for Windows). When I drop this component onto a multi-device-applicaiton form, set VisibleItems.Item1 and Item2 to true, and finally deploy it to an Android device I get the following errors: *.apk raised ececption class EComponentError with message 'A component named DEFAULT_MYTREEVIEWITEM already exists'. *.apk raised exception class Segmentation fault (11). *.apk raised exception class Illegal instruction (4).
Read More

Delphi Berlin: Why Icon Application and Launch Image do not work on iOS Simulator?

I'm defining the images for the app icon and the splash screen (iOS Simulator platform - iOS 10.1) as indicated in Project || Options -> Application. All images are correctly indicated in deployament and are being updated, but when running the application in iOS Simulator, the icon image and launch image are not updated and the default firemonkey icon is shown. Anyone have any idea what might be happening? Thanks.
Read More

How clear all forms and open a new one in Firemonkey?

Let's suppose the user is navigating throughout an Android/iOS app and open the following forms: Form A --> Form B --> Form C In Form C he press a button to logout from the app. This should clear all the previous forms (including Form C) and open a new Form (Signin Form D). So it would be something like that: Form A --> Form B --> Form C --> Press Logout Button Close Form A, B and C Open Form D Now if the user press the back button in Form D the app will be closed because there are no more forms in the task. I tried to open Form D and close previous ones but it didn't freed completely the previous forms. Anyway to achieve this for Android/iOS?
Read More

Delphi + iOS : How to translate this code to Delphi?

I try to translate header of FBAudienceNetwork.framework to Delphi typedef NS_ENUM(NSUInteger, FBNativeAdViewTag) { FBNativeAdViewTagIcon = 5, FBNativeAdViewTagTitle, FBNativeAdViewTagCoverImage, FBNativeAdViewTagSubtitle, FBNativeAdViewTagBody, FBNativeAdViewTagCallToAction, FBNativeAdViewTagSocialContext, FBNativeAdViewTagChoicesIcon, FBNativeAdViewTagMedia, }; /** Use this category to set tags for views you are using for native ad. This will enable better analytics. */ @interface UIView (FBNativeAdViewTag) @property (nonatomic, assign) FBNativeAdViewTag nativeAdViewTag; @end Delphi code const FBNativeAdViewTagIcon = 5; FBNativeAdViewTagTitle = 6; FBNativeAdViewTagCoverImage = 7; FBNativeAdViewTagSubtitle = 8; FBNativeAdViewTagBody = 9; FBNativeAdViewTagCallToAction = 10; FBNativeAdViewTagSocialContext = 11; FBNativeAdViewTagChoicesIcon = 12; FBNativeAdViewTagMedia = 13; type FBNativeAdViewTag = NSUInteger; FBNativeAdViewTag = interface(IObjectiveC) ['{F87149BD-3905-4566-B5B0-85F2C5ABB121}'] procedure setNativeAdViewTag(nativeAdViewTag: FBNativeAdViewTag); cdecl; function nativeAdViewTag: FBNativeAdViewTag; cdecl; end; I get error: Identifier redeclared 'FBNativeAdViewTag' How to translate this code to Delphi?
Read More