Category: StackOverflow

Delphi FMX TIdHTTP onWork, onWorkBegin, onWorkEnd not working

  

I’ve been fighting with TIdHTTP and Delphi FMX for a while and I don’t get good results, so, I don’t really know what to do.
So, the thing that I want to do is to show a ProgressBar while GETTING and POSTING with TIdHTTP. I’ve seen some codes online, that I’ve adapted, but nothing works.
But the problem is not only that the ProgressBar doesn’t work. The problem goes much further:
I tried to make an easier functionality, that only makes Visible:= true and Visible:= false when the IdHTTP is working.
So, I thought: If I make a get or a post, the TIdHTTP events OnWorkBegin, OnWork and OnWorkEnd should capture the action and make it visible/invisible.
So, the code I put was that:
procedure TF_FTP.IdFTP1WorkBegin(ASender: TObject; AWorkMode: TWorkMode; AWorkCountMax: Int64);
begin
ProgressBar1.Visible := true;
end;

procedure TF_FTP.IdFTP1Work(ASender: TObject; AWorkMode: TWorkMode;
AWorkCount: Int64);
begin
ProgressBar1.Visible := true;
end;

and
procedure TF_FTP.IdFTP1WorkEnd(ASender: TObject; AWorkMode: TWorkMode);
begin
ProgressBar1.Visible := false;
end;

What happened is, at the first get, the ProgressBar was visible because in the Form Design it is set as Visible. When it finishes, the ProgressBar gets invisible. Ok, well. But when I try to make another get or post, the ProgressBar never appears again.
If I make the ProgressBar invisible at the Form design, it never shows up.
I tried putting the Visible/Invisible on other IdHTTP events, as onConnected-onDisconnected, onBeforeGet-onAfterGet, … nothing seems to work. In addition, when I’m downloading the files, the Form freezes.
I don’t know what is happening, I’m running on Android64.
Thank you in advance.

Read More

how i can show data from database in delphi10.4.2 android?

  

I have problem with show data from data base in wwlayoutgrid in android version of my app. in windows version i dont have problem but in android i cannot show data.
i think database have not access in android version.
procedure TFrmSelectCustomer.BtnDetailsClick(Sender: TObject);
begin
CustomerInfo.Parent := Self;
CustomerInfo.Show();
CustomerInfo.Frame.LoadData(0);
end;

procedure TFrmSelectCustomer.BtnSortClick(Sender: TObject);
var
LstStr: TStringList;
OrderID: Integer;
begin
LstStr := TStringList.Create;
LstStr.Add(‘Customer Name’);
LstStr.Add(‘Number’);
LstStr.Add(‘Birth Date’);
if FOrder = ‘CustomerName’ then
OrderID := 0
else if FOrder = ‘Number’ then
OrderID := 1
else if FOrder = ‘BirthDate’ then
OrderID := 2;
TDialogBuilder.Create(Self).SetTitle(‘Sort By’).SetSingleChoiceItems
([LstStr.Strings[0], LstStr.Strings[1], LstStr.Strings[2]], OrderID)
.SetPositiveButton(‘NO’).SetNegativeButton(‘YES’,
procedure(Dialog: IDialog; Which: Integer)
begin
case Dialog.Builder.CheckedItem of
0:
FOrder := ‘CustomerName’;
1:
FOrder := ‘Number’;
2:
FOrder := ‘BirthDate’;
end;
ShowAllByFilterQuery(FormMain.QryCustomerList, EdtSearch.Text, FOrder);
end).Show;
LstStr.Free;
end;

thanks.

Read More

How to add task widget to lock screen on Android Phone?

  

How can I add task app to the lock screen (not the home screen) on Android:
I have tried all suggestions on the internet nothing works
https://github.com/ssaurel/LockScreenDevice
https://stackoverflow.com/questions/32526078/how-to-show-widgets-custom-layouts-on-lockscreen-or-on-homescreen-in-android-5
https://github.com/commonsguy/cw-omnibus/tree/master/AppWidget/TwoOrThreeDice

If it is possible to do it with flutter or with Delphi 10.4 please show me a code to do this so I can add it to my app.

Read More

Get Top and Left position of an FMX Control, based on screen bounds

  

I’m trying to place an outside program right into an FMX TPanel using SetWindowPOS from WinAPI.
In order to do that I need the exact Top and Left values of the TPanel to pass it to SetWindowPOS. However, this value is always according to its parent, so i.e. if the Tpanel’s parent is a TLayout and no margins are set, then the value of Top will be 0.
I need the Top value according to the screen.
I tried searching for that quite a bit but I can’t figure it out.
Any help with that would be greatly appreciated.

Read More

How can I create a fake integer property?

  

I’m trying to create a fake or pseudo property for child controls, and have tried to follow this article: https://edn.embarcadero.com/article/33448
However, that was written some years ago, so I don’t know how much Delphi might have changed since then in a way that could matter here.
Unlike the goal of that article, I’m trying to have a number property that is essentially the index of the control in its parent. This is for when a particular custom control (OrderLayoutObj) is the parent (although it might have applicability in other cases where I want to change the order of a control in its parent’s Children list without having to manually reorder the controls in the .fmx.)
In place of the article’s TAddPropertyFilter, this is my declaration and implementation. It matches the article’s one pretty closely, and I don’t think there is a problem with it. (Sorry for my umm, unconventional, naming and formatting.)
AddOrderProperty = class(TSelectionEditor, ISelectionPropertyFilter)
procedure FilterProperties(const ASelection: IDesignerSelections; const ASelectionProperties:IInterfaceList);
end;

procedure AddOrderProperty.FilterProperties(const ASelection:IDesignerSelections; const ASelectionProperties:IInterfaceList);
var OrderProperty: ControlOrderPropertyObj;
begin
if ASelection.Count<>1 then Exit;

if ASelection[0] is TControl then begin
if not (TControl(ASelection[0]).Parent is OrderLayoutObj) then Exit;

OrderProperty:=ControlOrderPropertyObj.Create(inherited Designer,1);
OrderProperty.Control:=TControl(ASelection[0]);
ASelectionProperties.Add(OrderProperty as IProperty);
end;
end;

I also don’t think that there’s a problem with my Register procedure:
procedure Register;
begin
DesignIntf.RegisterSelectionEditor(TControl,AddOrderProperty);
end;

I think the real problem is in my equivalent of the article’s TBaseComponentPropertyEditor and its descendant TControlParentProperty which were designed to allow a control to be selected. Instead of using that I’ve based it on TIntegerProperty, given that my additional property is an integer, and not knowing if the article’s author used what he did because he didn’t have a better descendant available at the time of the article.
(I did try try basing it on TBasePropertyEditor, but that didn’t work either, although the property did appear in the Object Inspector, and then produced an error. I don’t recall the exact details, though.)
ControlOrderPropertyObj = class(TIntegerProperty)
private
OrderControl: OrderLayoutObj;
ControlF: TControl;
procedure Control_Set(C:TControl);
protected
function GetEditValue(out Value:string):Boolean;
public
function GetName:string; override;
function GetValue:string; override;
procedure SetValue(const Value:string); override;
property Control:TControl read ControlF write Control_Set;
end; {AddControlFilter}

procedure ControlOrderPropertyObj.Control_Set(C:TControl);
begin
ControlF:=C;
OrderControl:=C.Parent as OrderLayoutObj;
end;

function ControlOrderPropertyObj.GetEditValue(out Value:string):Boolean; //This is a copy of the method from the article.
begin
Value:=GetValue;
Result:=True;
end;

function ControlOrderPropertyObj.GetName:string;
begin
Result:=’ControlIndex’;
end;

function ControlOrderPropertyObj.GetValue:string;
begin
GetValue:=OrderControl.PositionOf(Control).ToString;
end;

procedure ControlOrderPropertyObj.SetValue(const Value:string);
begin
OrderControl.ChangePosition(Control,Value.ToInteger);
end;

I think the problem is with another IProperty or other method that I haven’t overridden, but the only clue as to which one is that it’s producing an access violation (when clicking on the child component in the form editor) in line 752 of DesignEditors.pas. That’s on the Result:= line of this method:
function TPropertyEditor.GetPropType: PTypeInfo;
begin
Result := FPropList^[0].PropInfo^.PropType^;
end;

Although I’ve done it years ago, I’ve been unable to debug the design-time .bpl by setting Run>Parameters>Host name to Delphi itself.

Read More

Notify when there is a missing photo

  

In an android app that I made with Delphi I want to show photos from the database. When there is are 10 photos and let’s say 2 are missing I want to show a message which photos are missing and continue to show the 8 photos that are available.
So the filename is in the database but the real photo cant be found in the file.
This is the code on the client side
procedure TfmMain.Button42Click(Sender: TObject);
VAR
i : Integer;
FN : String;
begin
GetObjectFoto(Dm.mtObject.FieldByName(‘follownr’).value);
TV1.Items.Clear;
if dm.mtObjectphoto.RecordCount>0 then
begin
DM.mtObjectphoto.First;

for I := 0 to DM.mtObjectphoto.RecordCount-1 do
Begin
FN := ffotopath+DM.mtObjectphoto.FieldByName(‘filename’).Value;
If not (system.SysUtils.fileexists(FN)) then
try
DownloadFile(DM.mtObjectphoto.FieldByName(‘filename’).Value);
TV1.Items.Add;
TV1.Items.Items[i].Bitmap.LoadFromFile(fn);
TV1.Items.Items[i].Caption := ‘photo’;

end;

DM.mtObjectphoto.Next;
End;
end;

With ‘getobjectfoto’ i call the database for gathering the photos that belong to the object
this is the ‘downloadfile’ on the server-side
Begin
if fileexists(fphotomap+FilenameAtServer) then

Begin
Result := TMemoryStream.Create;
try
TMemoryStream(Result).LoadFromFile(fphotomap+FilenameAtServer);
FileSize := Result.Size;
Result.Position := 0;
except
FileSize := -1;

end;
End;

end;

fphotomap is just a directory on the server lets say C:\test
filenameatserver is the photoname that is saved in the database
Again the photo is not in the map but the data is in the database.
If i missed important data please let me know i correct it asap.

Read More

TWebBrowser local web pages have stopped working in Delphi 11 ( Alexandria )

  

Local file URLs have stopped working for the TwebBrowser component under Android32 bit applications when going from Delphi 10.4 to Delphi 11. I use TWebBrowser to deliver embedded help pages in my mobile app. The same code worked with with previous versions of Delphi.
Specifically urls that start with the file://data/user
The URLs are being parsed incorrectly so the path part throws away the /data bit.

Read More

Delphi Firemonkey Grid component scrolling

  

I am using firemonkey Delphi.
I have a Grid component and several edit boxes within a Listbox, each component occupying their own listboxitem within the listbox. My question is, when I scoll the listbox and my mouse moves over the grid component, the grid component captures my mousewheel scroll rather than the listbox. What I want to achieve is for the scroll function to remain with the listbox and only scroll the Grid when it/cell is clicked. If I set grid hittest to false it works fine but how do I go about detecting when my mouse is over the grid component to capture any mousedown events to reactivate the Grid for scrolling?
Here is the form I am using
object Form1: TForm1
Left = 0
Top = 0
Caption = ‘Form1’
ClientHeight = 736
ClientWidth = 636
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
DesignerMasterStyle = 0
object ListBox1: TListBox
Align = Client
Size.Width = 636.000000000000000000
Size.Height = 736.000000000000000000
Size.PlatformDefault = False
TabOrder = 1
DisableFocusEffect = True
DefaultItemStyles.ItemStyle = ”
DefaultItemStyles.GroupHeaderStyle = ”
DefaultItemStyles.GroupFooterStyle = ”
Viewport.Width = 616.000000000000000000
Viewport.Height = 732.000000000000000000
object ListBoxItem1: TListBoxItem
Size.Width = 616.000000000000000000
Size.Height = 65.000000000000000000
Size.PlatformDefault = False
TabOrder = 0
end
object ListBoxItem2: TListBoxItem
Position.Y = 65.000000000000000000
Size.Width = 616.000000000000000000
Size.Height = 65.000000000000000000
Size.PlatformDefault = False
TabOrder = 1
end
object ListBoxItem3: TListBoxItem
Position.Y = 130.000000000000000000
Size.Width = 616.000000000000000000
Size.Height = 65.000000000000000000
Size.PlatformDefault = False
TabOrder = 2
end
object ListBoxItem4: TListBoxItem
Position.Y = 195.000000000000000000
Size.Width = 616.000000000000000000
Size.Height = 65.000000000000000000
Size.PlatformDefault = False
TabOrder = 3
end
object ListBoxItem5: TListBoxItem
Position.Y = 260.000000000000000000
Size.Width = 616.000000000000000000
Size.Height = 500.000000000000000000
Size.PlatformDefault = False
TabOrder = 4
object Grid1: TGrid
Align = Client
CanFocus = True
ClipChildren = True
Size.Width = 616.000000000000000000
Size.Height = 500.000000000000000000
Size.PlatformDefault = False
TabOrder = 40
Viewport.Width = 596.000000000000000000
Viewport.Height = 475.000000000000000000
object Column1: TColumn
end
object Column2: TColumn
end
end
end
object ListBoxItem6: TListBoxItem
Position.Y = 760.000000000000000000
Size.Width = 616.000000000000000000
Size.Height = 65.000000000000000000
Size.PlatformDefault = False
TabOrder = 5
end
object ListBoxItem7: TListBoxItem
Position.Y = 825.000000000000000000
Size.Width = 616.000000000000000000
Size.Height = 65.000000000000000000
Size.PlatformDefault = False
TabOrder = 6
end
object ListBoxItem8: TListBoxItem
Position.Y = 890.000000000000000000
Size.Width = 616.000000000000000000
Size.Height = 65.000000000000000000
Size.PlatformDefault = False
TabOrder = 7
end
object ListBoxItem9: TListBoxItem
Position.Y = 955.000000000000000000
Size.Width = 616.000000000000000000
Size.Height = 65.000000000000000000
Size.PlatformDefault = False
TabOrder = 8
end
object ListBoxItem10: TListBoxItem
Position.Y = 1020.000000000000000000
Size.Width = 616.000000000000000000
Size.Height = 65.000000000000000000
Size.PlatformDefault = False
TabOrder = 9
end
object ListBoxItem11: TListBoxItem
Position.Y = 1085.000000000000000000
Size.Width = 616.000000000000000000
Size.Height = 65.000000000000000000
Size.PlatformDefault = False
TabOrder = 10
end
object ListBoxItem12: TListBoxItem
Position.Y = 1150.000000000000000000
Size.Width = 616.000000000000000000
Size.Height = 65.000000000000000000
Size.PlatformDefault = False
TabOrder = 11
end
end
end

Read More

"E2597 SysInit.o: error adding symbols: File in wrong format" when compiling a 32-bit Android app

  

I get this error when trying to compile a 32-bit Android application:

[DCC Error] E2597 c:\program files (x86)\embarcadero\studio\21.0\lib\Android\debug\SysInit.o: error adding symbols: File in wrong format

When compiling for 64-bit, there is no problem.
I have tried reinstalling the Android platform, and using a different SDK version, but the issue is the same.
How do I resolve this?

Read More

How can I write an event in FireMonkey when Windows time changes? [duplicate]

  

In Delphi VCL, using this code, I can capture Windows time changes.
uses Winapi.Messages;

private
procedure WMTimeChange(var Msg: TMessage); message WM_TIMECHANGE;

procedure TForm1.WMTimeChange(var Msg: TMessage);
begin
inherited;
ShowMessage(‘time changed’);
end;

But, it doesn’t work in FireMonkey.
What is the equivalent for FireMonkey?

Read More

Drawing a line in a Bitmap using X and Y coordinates

  

I have a transparent bitmap containing a thin line only. I’ve extracted the X,Y coordinates using TBitmapData in Delphi FMX. I have the X and Y coordinates of each pixel of the line in the Bitmap. My question is how to Draw again the same line in that Bitmap using the X,Y coordinates with a different color ? Or perhaps plotting it in an empty Bitmap

Read More

Delphi 10.4.2 and IOS SDK 15.2

  

I’m using Delphi 10.4.2 and have done an iOS SDK update to version 15.2.
I am using a server in MacInCloud with macOS Monterey to compile.
During compilation I get the following error:
[DCC Error] E2597 ld: warning: directory not found for option ‘-FC:UserDocumentsEmbarcaderoStudioSDKsSystemLibraryPrivateFrameworksDocumentManager.framework’
ld: file not found: /usr/lib/system/libcache.dylib for architecture arm64
[DCC Fatal Error] F2588 Linker error code: 1 ($00000001)

What can be done about it ?

Read More

How can enable HotSpot on android device by delphi code

  

By this delphi code I can enable wifi on android device.
var WiFIServiceNative: JWifiManager;

begin
WiFIServiceNative :=
JWifiManager.Wrap(TAndroidHelper.Context.getSystemService(TJContext.JavaClass.WIFI_SERVICE));
if Assigned(WiFIServiceNative) then
TJWifiManager.JavaClass.WIFI_STATE_ENABLED
end;

How can enable hotspot by delphi code.

Read More