Category: StackOverflow

FireMonkey tRectangle with tLabel child

I am coding a custom control based on tRectangle: tMyRect = class (tRectangle) On the tMyRect Constructor, I create a tLabel: fRectLabel := tLabel.Create (Self); and then set some properties for it. At runtime, the tLabel is not showed according to the properties settings, neither responds to the speedkey. Follows the complete code: unit frmMyRect; interface uses FMX.Controls, FMX.Controls.Presentation, FMX.Forms, FMX.Layouts, FMX.Objects, FMXFMX.StdCtrls, FMX.Types,System.Classes, System.UITypes; type tfrmMyRect = class (tForm) procedure FormCreate (Sender: tObject); end; tMyRect = class (tRectangle) fRectLabel : tLabel; constructor Create (aOwner: tComponent); end; var formMyRect: tfrmMyRect; implementation {$R *.fmx} var MyRect : tMyRect; procedure tformMyRect.FormCreate (Sender: tObject); begin MyRect := tMyRect.Create (Self); MyRect.Parent := frmMyRect; end; { FormCreate } constructor tMyRect.Create (aOwner: tComponent); begin inherited; Align := tAlignLayout.Center; CanFocus := True; Height := 23; Width := 80; fRectLabel := tLabel.Create (Self); with fRectLabel do begin Align := tAlignLayout.Center; AutoSize := True; FocusControl := Self; HitTest := True; Parent := Self; Text := 'Labe&l'; with TextSettings do begin FontColor := TAlphaColorRec.Blue; WordWrap := False; Font.Style := [TFontStyle.fsBold]; end; end; end; { Create } end. I appreciate if someone can clarify why the tLabel does not behave as expected.
Read More

Open and read a file in firemonkey

What is wrong in this code ? I don't understend, if I remove the "Try" my app dont open, and if don't remove always appear "need login" ... procedure TF_login.FormActivate(Sender: TObject); var Result: Integer; TextFile: TStringList; VarArquivo: string; text: string; dataI, dataF : string; begin TextFile := TStringList.Create; VarArquivo := System.IOUtils.TPath.GetDocumentsPath + PathDelim + 'Limit.txt'; try TextFile.LoadFromFile(VarArquivo); text := TextFile.Text; // ShowMessage(TextFile.Text); // there is the text // ShowMessage(text); // there is the text dataI := FormatDateTime('dd/mm/yyyy', Now); dataF := FormatDateTime('dd/mm/yyyy', StrToDate(text)); Result := CompareDate(StrToDate(dataI), StrToDate(dataF)); ShowMessage(dataF +' data f'); ShowMessage(dataI +' data I'); if ( Result = LessThanValue ) then begin ShowMessage('data F low'); end else begin ShowMessage('data F high'); F_inicio.Show; end; FreeAndNil(TextFile); except on E: Exception do ShowMessage('An error happened!' + sLineBreak + '[' + E.ClassName + '] ' + E.Message); end; end; The error : [EConvertError] '09/11/2019' is not a valid date to create the file, i do: procedure TF_login.btn_entrarClick(Sender: TObject); var data : tdatetime; Resposta, data_s: string; begin PathFile := System.IOUtils.TPath.GetDocumentsPath; NameFile := 'Limit.txt'; data := Now; //data actual data := IncMonth(data, 2); data_s := FormatDateTime('dd/mm/yyyy', data); TFile.WriteAllText(TPath.Combine(PathFile, NameFile), data_s ); F_inicio.Show; end; The file exists, because the first (and second) ShowMessage (what is commented) show me the "09/11/19" but the third and fourth not appear to me... OBS: Delphi 10.3 (RIO), Plataform: Android
Read More

How to alter the sensitivity of a FMX.TStringGrid to better respond to "click" rather than "scroll"

We have a Delphi 10.3 Rio FireMonkey app. Part of the main form is a TStringGrid containing a list of materials. The user can touch "click" into a quantity cell to enter the amount of material they wish to use, or they can touch "scroll" the list up and down if there is more than the visible number of lines. The problem we have heard from our Android tablet users, is that it seems very unresponsive when trying to enter the quantity. They have to press several times into the cell before it goes into edit mode and allows them to enter a value. iPad and Windows users are not reporting this problem. We've tried several different Android devices, and they all exhibit the same issue. From discussions among ourselves, we've hit on the idea that the component is responding to the touch as the beginning of a scroll rather than the click of the cell, and we are wondering if there is a way to alter how the component behaves, or add events to either the TStringGrid or the TFloatColumn that would better detect the click and force it to edit the cell based on the hit test?
Read More

TScrollBox or TChart memory leak (FMX, C++)

I've been trying to find a memory leak on iOS and i'm 99% it is either in a TScrollBox or in a TChart. The action that leads to the crash is simple scrolling back and forth across the TChart. The app behaves well in Win32 and memory useage is stable. The crash cause on iOS is EXC_RESOURCE -> myappname[5548] exceeded mem limit: ActiveHard 1400MB (fatal) per Xcode Console. To exclude my spaghetti code as the culprit i created a simple project to reproduce the error and it crashes too. Below are snips from the Xcode Console output. I get tons of assertions, then the Received memory warning, then the iOS kernal kills my app (Project1). default 20:28:26.180333 -0500 assertiond [Project1:7693] Activate assertion: <BKProcessAssertion: 0x12b0102c0; "com.apple.UIKit.KeyboardManagement.message" (finishTask:180s); id:…8EA7F5E94DD5> default 20:28:26.180542 -0500 assertiond [Project1:7693] Setting jetsam priority to 10 [0x10108] default 20:28:26.182151 -0500 assertiond [Project1:7693] Deactivate assertion: <BKProcessAssertion: 0x12b0102c0; "com.apple.UIKit.KeyboardManagement.message" (finishTask:180s); id:…8EA7F5E94DD5> default 20:28:26.182312 -0500 assertiond [Project1:7693] Setting jetsam priority to 10 [0x10100] default 20:28:26.183307 -0500 assertiond [Project1:7693] Remove assertion: <BKProcessAssertion: 0x12b0102c0; "com.apple.UIKit.KeyboardManagement.message" (finishTask:180s); id:…8EA7F5E94DD5> default 20:28:32.609723 -0500 Project1 Received memory warning. Then a short time later i see the following console message: default 20:28:45.881914 -0500 kernel EXC_RESOURCE -> Project1[7693] exceeded mem limit: ActiveHard 1400 MB (fatal). My crash test app is a simple Firemonkey app built in C++ Builder 10.3.2. A) Put a TPanel on the form (Panel1). B) Put a TScrollBox on Panel1 (ScrollBox1). Set its align to Contents. C) Put a TLayout on ScrollBox1 (Layout1). Set its align to None. Set its width to 2100. D) Put a TChart on Layout1. Set its height to 200, width 7300. Set its align to None. E) Add a TToolBar to Form1 and put a TButton on it. F) Then put this code in the TButton's click event: Form1->Layout1->Position->X = 0; Form1->ChartTest->Position->Y = 0; Form1->ChartTest->Position->X = 0; TLineSeries *series1 = new TLineSeries(Form1); TLineSeries *series2 = new TLineSeries(Form1); TLineSeries *series3 = new TLineSeries(Form1); TLineSeries *series4 = new TLineSeries(Form1); series1->Color = claBlue; series2->Color = claRed; series3->Color = claBlueviolet; series4->Color = claAqua; double x, y; for (int i = 0; i < 1000; i++) { x = i; y = Random(5000); series1->AddXY(x,y); y = Random(5000); series2->AddXY(x,y); y = Random(5000); series3->AddXY(x,y); y = Random(5000); series4->AddXY(x,y); } Form1->ChartTest->AddSeries(series1); Form1->ChartTest->AddSeries(series2); Form1->ChartTest->AddSeries(series3); Form1->ChartTest->AddSeries(series4); G) And now, with your iOS device connected to your mac and Xcode Console open, filter the Console output on "Project1" if that is what you named it. Then run the app and scroll backwards/forwards and/or up/down (also change orientation if you want back and forth). You will see tons of assertions. Eventually (takes around 2-3 minutes of this harassment to make it crash) it will eat up enough memory that it crashes. I think the memory leak is in the TeeChart most likely, maybe in the TScrollBox? thanks, russ
Read More

After redeploying a FireMonkey app to my physical device, GetDocumentsPath always contains older asset files

I'm developing a Delphi FireMonkey app and I'm testing it using some assets. It seems to work fine. However, now I completely removed all assets from the Deployment Manager and whenever I remove the app from my device (using some ADB shell commands, I can verify that the app directory is completely removed) and run the app again in debug from the IDE, some older assets appear again. (in fact, 1 SQLite database file and a tmp file representing the form savestate. They have normal file attributes, but the file dates are 1970-01-19). Using the ADB shell command again, I notice these files reappear BEFORE the app hits the StartupCopy unit initialization! I've verified many things, but I have no idea where they keep re-appearing from (from Android itself or transferred from my PC, but since I removed them all, this is very unlikely). I'm very puzzled with this. If I delete only the data files from the app on the device, this does not happen. Only when I completely remove the app. Is there a backup/init/loading mechanism on Android itself that might cause this? Since my device is not rooted, looking on the device itself is limited. ls -l of my app's directory: -rw------- 1 u0_a289 u0_a289 4 1970-01-19 03:56 FM_TMainForm_MainForm.TMP -rw------- 1 u0_a289 u0_a289 217088 1970-01-19 03:45 dancegenie.sqlite
Read More

TDirectory::GetFiles listing ignoring case on iOS (FMX, C++)

The code below lists files that have extension .cfg and it works fine on Win32. But, on iOS if i have a file that a user named with caps for the extension (e.g. test.CFG) then i miss it. I found this post using Delphi that might work using TDirectory::TFilterPredicate but i don't know how to implement in C++Builder. TStringDynArray list; TSearchOption searchOption; UnicodeString DocsPath; int lenDocsFolder; DocsPath = System::Ioutils::TPath::GetDocumentsPath(); lenDocsFolder = DocsPath.Length(); searchOption = TSearchOption::soTopDirectoryOnly; try { list = TDirectory::GetFiles(DocsPath, "*.cfg", searchOption); } catch (...) { ShowMessage("Incorrect path or search mask"); return; } I suppose i can just run a *.cfg block of code followed by a *.CFG but i'm hoping there is a cleaner approach.
Read More