Jump to content

Yaron

Members
  • Content Count

    275
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by Yaron

  1. Using "with" can clean up the code to make it easier to read, but ever since the dawn of Delphi, it had a severe downside that "with" hinders debugging. You can't simply hover with the mouse cursor over a variable to get its value or use evaluate/modify on the variable itself without having to copy & paste the record/class name first. And now I've encountered a more recent issue with refactoring. If you use refactoring to rename a variable inside a record, it will miss any instances where the record was used with a "with" statement. Will this ever be improved? If not, what are your recommendations?
  2. I am using MARS as a back-end for a Web Application (processing post/get requests from HTML forms and outputting HTML based on the form input). I am currently deploying MARS as an IIS module DLL simply because I already have an IIS7.5 server installed and I wanted the free SSL security that comes with this type of setup. However, I had one instance where I was getting a "500" error from IIS and the only way to resolve it was to restart the application pool. Assuming my code is bug-free, what is the most reliable and best performance (for concurrent usage by multiple users) method to deploy MARS with SSL on a windows machine?
  3. Yaron

    With's the deal with "With"?

    I'm aware of past discussion with regards to debugging, I was just not aware that it also broke refactoring which is why I started the topic. Was there ever an official reply on an intent to resolve some of these issues?
  4. Yaron

    The 9 Hints in MARS

    I did, but it will get overwritten the next time I pull the code to get the latest version...
  5. Any chance you can make a tutorial video showing your preferred deployment method?
  6. We all knew it would come this August, but now the Google Play store is showing warning notifications on new uploads: And to top it off, there's a new warning that I have no idea how to address (if it's even possible) with Delphi:
  7. Thank you Peter & Remy, I wasn't aware that TCanvas was sharing resources, the D7 documentation on lock/unlock refers to use lock to prevent other threads from writing to the canvas, but since my code wasn't accessing the canvas from outside the thread, I didn't think locking was mandatory. I have now changed the code to lock all 3 canvases outside the thread loop. Sherlock: It's funny how one person's confusing syntax is exactly the opposite for another person, I hate using "not" in any boolean check because for me it's confusing with logical (bitwise) operators. John Kouraklis I'm not sure what you mean. I use "csThumbRenderer" TCriticalSection in a try/finally block to copy over the contents of TBitmaps from the main thread. I use the same critical section in the main thread as well when accessing these bitmaps, so there should be no case where the bitmaps are used concurrently by more than one thread.
  8. I am trying to upload an image from an html form (see below) to a MARS server. Previously, I was able to get this working when the client was written in Delphi, but now the client is a standard browser and the code fails (LParam.isFile returns false). HTML form: <form method="post"> <input type="text" name="ImageName" required><br> <input type="file" accept="image/jpeg" name="ImageFile" required> </form> The code I used to get the image that doesn't seem to work in this case : var lParam : TFormParam; mStream : TMemoryStream; begin For lParam in aParams do Begin If (SameText(lParam.FieldName, 'ImageFile')) then Begin If (LParam.isFile) then Begin mStream := TMemoryStream.Create; mStream.Write(lParam.AsFile.Bytes,Length(lParam.AsFile.Bytes)); mStream.Position := 0; Try mStream.SaveToFile('d:\test.jpg'); Finally mStream.Free; End; End; End; end; Any ideas?
  9. I believe that I solved this issue, I was missing enctype="multipart/form-data" in the form's statement.
  10. Is there a way to shorten the URL required to access the MARS server? What I did so far was to modify FEngine.AddApplication('DefaultApp', '/v', [ 'Server.Resources.*']); in "Server.Ignition". Ideally, I would like to eliminate the "/rest" and application name entirely, so the entry point would be whatever I define in [Path('')].
  11. For reasons I don't understand, the issue in the screenshot occasionally shows up. Then, when an exception is raised or when I place breakpoints, it causes them to trigger/show on the wrong line of code. Any idea how to resolve this issue?
  12. I am writing a server using MARS with the client being a web browser (e.g. firefox) sending form data to the server. I don't want every user to be able to access the form, so I need to implement a login/authentication system. The authentication demo code I've seen ('MARS-Repository\MARS\Demos\Authorization\') seems to require using MARS client-code, which I don't think is possible if the client is a web browser. Do I need to write my own authentication code or is there some way I can leverage MARS's authentication code for this purpose?
  13. Is there documentation on how to use MARS to embed data in a cookie and retrieve it on subsequent calls? And of course, any additional sample code would be a blessing.
  14. I am developing a cross-platform remote control app for my Windows PC media player: https://play.google.com/store/apps/details?id=com.inmatrix.ZP_Remote However, I have a user running Android 9 that reports that right after the splash screen (delphi's built-in splash screen, no custom code), all they see is a gray screen. Since the user is on a rooted phone, I provided a debug APK with code that outputs progress to a log file, however the log file is never created. The only thing I can compare it to is trying to run the App on the Nox emulator running Android 7, which instantly crashes after the splash screen without reaching the first line of code on even a blank application (new multi-device application, with no additional code): Here is the pertinent code that should at least output one line of debug code (which works just fine on all devices I could test locally): program ZP_Remote; {$R *.dres} uses FMX.Forms, FMX.Types, misc_functions, System.IOUtils, System.SyncObjs, MainUnit in 'MainUnit.pas' {MainForm}, transunit in 'transunit.pas'; {$R *.res} begin csDebug := TCriticalSection.Create; clientStopWatch.Start; UserDataPath := System.IOUtils.TPath.GetHomePath+System.IOUtils.TPath.DirectorySeparatorChar+clientName+System.IOUtils.TPath.DirectorySeparatorChar; {$IFDEF TRACEDEBUG}AddDebugEntry('DPR:Start');{$ENDIF} FMX.Types.GlobalUseGPUCanvas := True; // 25->840fps! but messes with font rendering?!? Application.Initialize; {$IFDEF TRACEDEBUG}AddDebugEntry('DPR:Initialized');{$ENDIF} Application.FormFactor.Orientations := [TFormOrientation.Portrait]; {$IFDEF TRACEDEBUG}AddDebugEntry('DPR:Form orientation set');{$ENDIF} Application.CreateForm(TMainForm, MainForm); {$IFDEF TRACEDEBUG}AddDebugEntry('DPR:Form created, ready to run');{$ENDIF} Application.Run; {$IFDEF TRACEDEBUG}AddDebugEntry('DPR:Last line');{$ENDIF} end. And here is the code that writes the debug output: procedure AddDebugEntry(S : String); const UTF8BOM : Array[0..2] of Byte = ($EF,$BB,$BF); Var FileName : String; fStream : TFileStream; sAnsi : UTF8String; S1 : String; begin If csDebug <> nil then csDebug.Enter; Try if UserDataPath <> '' then Begin FileName := UserDataPath+clientDebugFile; If FileExists(FileName) = True then Begin Try fStream := TFileStream.Create(FileName,fmOpenWrite); Except fStream := nil; End; End else Begin Try fStream := TFileStream.Create(FileName,fmCreate); fStream.Write(UTF8BOM,3); Except fStream := nil; End; End; If fStream <> nil then Begin S1 := IntToStr(clientStopWatch.ElapsedMilliseconds); While Length(S1) < 12 do S1 := ' '+S1; S := {$IFDEF DEBUGDATE}DateToStr(Date)+' '+TimeToStr(Time)+' '+{$ENDIF}'['+S1+'] : '+S; sAnsi := UTF8Encode(S)+#13#10; fStream.Seek(0,soFromEnd); fStream.Write(sAnsi[Low(sAnsi)],Length(sAnsi)); fStream.Free; End; End; Finally If csDebug <> nil then csDebug.Leave; End; end; I welcome any advice on the best practices to diagnose and resolve such issues when access to the devices is severely limited.
  15. Please ignore this post, the issue was a combination of a bug and the user's inability to find the output log.
  16. I was able to obtain some logcat/event, any idea what's going on? Logcat: 05-13 16:00:47.545 I/ActivityManager( 1383): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity bnds=[37,1730][238,2028]} from uid 10015 05-13 16:00:47.636 I/ActivityManager( 1383): Start proc 14206:com.inmatrix.ZP_Remote/u0a227 for activity com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity 05-13 16:00:48.297 W/linker (14206): Warning: "/data/app/com.inmatrix.ZP_Remote-S-1zk8LZ5cw0Sxl-7bv-GA==/lib/arm/libZP_Remote.so" unused DT entry: DT_RPATH (type 0xf arg 0x145ae) (ignoring) 05-13 16:00:49.598 D/SurfaceFlinger( 814): duplicate layer name: changing SurfaceView - com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity to SurfaceView - com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity#1 05-13 16:00:49.599 D/SurfaceFlinger( 814): duplicate layer name: changing Background for -SurfaceView - com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity to Background for -SurfaceView - com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity#1 05-13 16:00:49.994 I/ActivityManager( 1383): Displayed com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity: +2s446ms 05-13 16:00:50.100 W/SurfaceFlinger( 814): Attempting to set client state on removed layer: Splash Screen com.inmatrix.ZP_Remote#0 05-13 16:00:50.100 W/SurfaceFlinger( 814): Attempting to destroy on removed layer: Splash Screen com.inmatrix.ZP_Remote#0 05-13 16:00:57.071 E/BufferQueueProducer( 814): [SurfaceView - com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity#1] disconnect: not connected (req=1) 05-13 16:00:58.326 W/InputDispatcher( 1383): channel '3be32e5 com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9 05-13 16:00:58.326 E/InputDispatcher( 1383): channel '3be32e5 com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity (server)' ~ Channel is unrecoverably broken and will be disposed! 05-13 16:00:58.329 I/ActivityManager( 1383): Process com.inmatrix.ZP_Remote (pid 14206) has died: cch CRE 05-13 16:00:58.329 I/WindowManager( 1383): WIN DEATH: Window{3be32e5 u0 com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity} 05-13 16:00:58.329 W/InputDispatcher( 1383): Attempted to unregister already unregistered input channel '3be32e5 com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity (server)' 05-13 16:00:58.349 W/SurfaceFlinger( 814): Attempting to destroy on removed layer: AppWindowToken{58e86aa token=Token{2ad595 ActivityRecord{e1ab14c u0 com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity t9944}}}#0 Events: 05-13 15:56:13.909 I/am_create_activity( 1383): [0,177586847,9925,com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity,android.intent.action.MAIN,NULL,NULL,270532608] 05-13 15:56:13.971 I/am_proc_start( 1383): [0,11738,10227,com.inmatrix.ZP_Remote,activity,com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity] 05-13 15:56:14.131 I/am_proc_bound( 1383): [0,11738,com.inmatrix.ZP_Remote] 05-13 15:56:14.143 I/am_restart_activity( 1383): [0,177586847,9925,com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity] 05-13 15:56:14.145 I/am_set_resumed_activity( 1383): [0,com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity,minimalResumeActivityLocked] 05-13 15:56:16.473 I/sysui_multi_action( 1383): [319,268,321,116,322,2583,325,94229,757,761,758,7,759,1,806,com.inmatrix.ZP_Remote,871,com.embarcadero.firemonkey.FMXNativeActivity,904,com.google.android.apps.nexuslauncher,905,0,945,247,1320,12,1321,1] 05-13 15:56:16.475 I/am_activity_launch_time( 1383): [0,177586847,com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity,2583] 05-13 15:56:22.553 I/am_finish_activity( 1383): [0,177586847,9925,com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity,app-request] 05-13 15:56:22.555 I/am_pause_activity( 1383): [0,177586847,com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity,userLeaving=false] 05-13 15:56:23.195 I/am_destroy_activity( 1383): [0,177586847,9925,com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity,finish-imm:activityIdleInternalLocked] 05-13 15:56:24.232 I/am_proc_died( 1383): [0,11738,com.inmatrix.ZP_Remote,900,17] 05-13 16:00:47.559 I/am_create_activity( 1383): [0,236630348,9944,com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity,android.intent.action.MAIN,NULL,NULL,270532608] 05-13 16:00:47.636 I/am_proc_start( 1383): [0,14206,10227,com.inmatrix.ZP_Remote,activity,com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity] 05-13 16:00:47.854 I/am_proc_bound( 1383): [0,14206,com.inmatrix.ZP_Remote] 05-13 16:00:47.865 I/am_restart_activity( 1383): [0,236630348,9944,com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity] 05-13 16:00:47.865 I/am_set_resumed_activity( 1383): [0,com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity,minimalResumeActivityLocked] 05-13 16:00:49.993 I/sysui_multi_action( 1383): [319,336,321,104,322,2446,325,94503,757,761,758,7,759,1,806,com.inmatrix.ZP_Remote,871,com.embarcadero.firemonkey.FMXNativeActivity,904,com.google.android.apps.nexuslauncher,905,0,945,311,1320,12,1321,1] 05-13 16:00:49.994 I/am_activity_launch_time( 1383): [0,236630348,com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity,2446] 05-13 16:00:56.363 I/am_finish_activity( 1383): [0,236630348,9944,com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity,app-request] 05-13 16:00:56.365 I/am_pause_activity( 1383): [0,236630348,com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity,userLeaving=false] 05-13 16:00:56.987 I/am_destroy_activity( 1383): [0,236630348,9944,com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity,finish-imm:activityIdleInternalLocked] 05-13 16:00:58.329 I/am_proc_died( 1383): [0,14206,com.inmatrix.ZP_Remote,900,17]
  17. I managed to get a logcat of my app not loading in Nox (this also happens with a blank app): I/ActivityManager( 2149): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity bnds=[930,370][1189,525]} from uid 1000 on display 0 I/ActivityManager( 2149): Start proc 4473:com.inmatrix.ZP_Remote/u0a44 for activity com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity D/houdini ( 4473): [4473] Added shared library /data/app/com.inmatrix.ZP_Remote-1/lib/arm/libZP_Remote.so for ClassLoader by Native Bridge. F/DEBUG ( 4489): pid: 4473, tid: 4473, name: atrix.ZP_Remote >>> com.inmatrix.ZP_Remote <<< W/ActivityManager( 2149): Force finishing activity com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity I/WindowManager( 2149): Failed to capture screenshot of Token{1a08a1d ActivityRecord{48bc2f4 u0 com.inmatrix.ZP_Remote/com.embarcadero.firemonkey.FMXNativeActivity t7 f}} appWin=Window{3b58c89 u0 Starting com.inmatrix.ZP_Remote} drawState=4 I/ActivityManager( 2149): Process com.inmatrix.ZP_Remote (pid 4473) has died W/ActivityManager( 2149): Ignoring remove of inactive process: ProcessRecord{98f6a49 0:com.inmatrix.ZP_Remote/u0a44} I'm not proficient enough to understand the debug out, can anyone shed any light?
  18. I don't think the AppBundle will become mandatory, but I wouldn't put it past google to down-grade your position in search results based on it.
  19. I am trying to create a really simple TCP/IP connection to a server using Indy on Android. All the communication between the client and server is text based. I tried adjusting the code on Remi's answer from this thread to my needs: https://stackoverflow.com/questions/17372366/delphi-indy-tidtcpclient-reading-data However, what happens is that "FConn.IOHandler.ReadLn;" is blocking (at least under Android), so when the App closes and I try to terminate the thread, calling the thread's "WaitFor" method triggers a freeze as the thread never leaves the blocking "ReadLn" and never terminates. Is there a way to instantly stop ReadLn from waiting so the thread could terminate cleanly? Or should I use "FConn.IOHandler.ReadBytes" instead? P.S. I read this thread: https://stackoverflow.com/questions/12507677/terminate-a-thread-and-disconnect-an-indy-client And in it Remy writes that "Disconnecting the client will cause ReadLn() to raise an exception inside the thread.", which is not the case for me under Android (I'm trying to catch the exception and write a log entry when it triggers, but nothing gets written). I also tried wrapping the disconnect method in a "try except" block, but it's not triggering any exception. The code I'm using: procedure TMainForm.CreateTCPIPConnection; var B : Boolean; begin IdTCPClient.Host := AddressEdit.Text; IdTCPClient.Port := StrToIntDef(PortEdit.Text,4769); B := False; Try IdTCPClient.Connect; except on E: Exception do Begin B := True; {$IFDEF TRACEDEBUG}AddDebugEntry('TCP/IP connect exception : '+E.Message);{$ENDIF} End; end; If B = False then Begin If Assigned(ZPReadThread) = False then try ZPReadThread := TReadingThread.Create(IdTCPClient); ZPReadThread.OnData := DataReceived; ZPReadThread.Start; except on E: Exception do Begin IdTCPClient.Disconnect; {$IFDEF TRACEDEBUG}AddDebugEntry('TCP/IP exception creating read thread : '+E.Message);{$ENDIF} End; end; End; end; procedure TReadingThread.Execute; begin {$IFDEF TRACEDEBUG}AddDebugEntry('Read thread created');{$ENDIF} while not Terminated do begin {$IFDEF TRACEDEBUG}AddDebugEntry('Read thread ReadLn (before)');{$ENDIF} Try FData := FClient.IOHandler.ReadLn; Except on E: Exception do Begin {$IFDEF TRACEDEBUG}AddDebugEntry('TCP/IP IOHandler.ReadLn exception : '+E.Message);{$ENDIF} End; End; //FClient.IOHandler.ReadBytes(AData, sizeof(TWaveFormSample), False); {$IFDEF TRACEDEBUG}AddDebugEntry('Read thread ReadLn (after)');{$ENDIF} if (FData <> '') and Assigned(FOnData) then Synchronize(DataReceived); //Sleep(1); end; {$IFDEF TRACEDEBUG}AddDebugEntry('Read thread about to terminate');{$ENDIF} end; procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction); begin If IdTCPClient.Connected = True then Begin try IdTCPClient.Disconnect; except on E: Exception do Begin {$IFDEF TRACEDEBUG}AddDebugEntry('TCP/IP Disconnect exception : '+E.Message);{$ENDIF} End; end; End; if Assigned(ZPReadThread) then Begin {$IFDEF TRACEDEBUG}AddDebugEntry('Terminating Read thread');{$ENDIF} ZPReadThread.Terminate; {$IFDEF TRACEDEBUG}AddDebugEntry('Waiting for read thread termination');{$ENDIF} ZPReadThread.WaitFor; {$IFDEF TRACEDEBUG}AddDebugEntry('Finished waiting for read thread termination');{$ENDIF} FreeAndNil(ZPReadThread); End; end;
  20. Yaron

    Using Indy for cross-platform TCP/IP

    I am writing a remote control App that controls a PC. I am sending commands over TCP/IP each time a user clicks a UI button and at the same time, listening to responses to my commands. Presently, I am getting responses in the background "reading" thread and sending the command in the main thread. After reading your comments I realize my issue is further complicated, as your recommend not calling any TCP/IP function at all in my main thread, which means my Read function can't be blocking at all, otherwise the user will experience input-lag. Is it safe to call "IdTCPClient.IOHandler.WriteLn" in the main thread? If not, what is the best approach to check if there is data waiting without blocking?
  21. When specifying the multiple resolution images in the project's options page, there doesn't seem to be any relations between the device's screen resolution and the resolution of the splash image. For example, on a Note4 device with a screen resolution of 1440x2560, the "470x320" (blurry) splash screen is displayed. Is there a way to influence this selection?
  22. I actually posted this question on stack overflow a while back, got what I thought was a working answer but over time realized that on different devices, waiting for "onIdle" doesn't actually work. Here's the background, my app on first-load does some time-consuming (3-8 sec) pre-calculations so subsequent runs would be much faster. During this processing period, I want to show a "loading %" track-bar. However, for the life of me, I haven't been able to find the exact moment my form is visible and responsive for action. I tried different approaches: 1. waiting for "OnActivate" event. 2. Implementing IFMXApplicationEventService.SetApplicationEventHandler and waiting for "TApplicationEvent.BecameActive". 3. Waiting for "TApplicationEvent.BecameActive" to trigger and then waiting for 3 "OnIdle" events to trigger (2 OnIdle events were not enough for my Galaxy Note 4 device). Only #3 sort of worked on most devices using Delphi 10.2.3, but then when I upgraded to Delphi 10.3.1 even that stopped working (my progress bar shows up but the screen stops updating, so the bar remains on 0% until the pre-calculation function completes, even when calling Application.ProcessMessages after each update and no other code running in the background). Is there a better solution to know the exact moment my app will start responding to screen updates on launch under Android?
  23. I was doing this in v10.2.3 and it was not stable, I chronicled my experiences here: https://stackoverflow.com/questions/52168940/is-png-decoding-not-thread-safe-under-android After replacing TBitmap PNG decoding with JBitmap, the issue was resolved, so I do believe that at least in v10.2.3 TBitmap is not thread safe.
  24. Yaron

    Issue with code-editor toolbars

    I just realized that the "palette" window switches context between new project files or components based on whether you're editing code or the form. 🤯
×