All Activity
This stream auto-updates
- Past hour
-
Yes, I did. I have a feeling that if I would newly rewrite the same code in Athens - that it would work normally (as it does in Alexandria). I will try that tomorrow and let you know...
- Today
-
Here are a few more projects: PLUA: Lua for Pascal PLUA is a lightweight and powerful 📦 that integrates LuaJIT scripting into Delphi, enabling you to easily add a scripting layer to your Delphi apps. Whether you're building dynamic software 🖥️, adding mod support 🛠️, or simply looking for a way to make your apps more flexible and customizable, PLUA makes this possible through simple, straightforward APIs. CPas: Static C Libraries for Delphi A collection of hand-picked, high-quality C libraries, compiled into a single translation unit and seamlessly integrated into Delphi. This approach eliminates the need for external DLLs, runtime extraction, or loading them in memory, simplifying the development process and reducing potential compatibility issues, such as antivirus 🛡️ interference. Mamba Game Toolkit: Advanced 2D Game Library for Delphi. Mamba Game Toolkit (MGT) is a sophisticated yet easy-to-use 2D game development library for Delphi. Tailored to meet the needs of Windows developers, MGT offers a streamlined approach to building 2D games, focusing on simplicity, performance, and reducing external dependencies. With everything linked directly into the executable️, it eliminates the need for runtime DLLs, simplifying deployment and enhancing the overall stability and reliability of your projects. Enjoy! 👀
-
There is no possible way it could have worked before the way you showed it earlier. That code had logic bugs in the communications. That is because you are using ReadString() incorrectly. You are writing the JSON as a string without sending either a leading size or a terminator, so the server will have no way to know when the string actually ends. But you are not telling ReadString() how many bytes to read, and when the ABytes parameter is <= 0 then ReadString() will just return a blank string since it has nothing to read. Hence the parse error. The examples I gave you in my previous reply 1) use WriteLn() and ReadLn() to send/read the JSON with a terminating CRLF, and 2) use Write(TStream) and ReadStream/ReadString() to send/read the JSON with a leading size. Makes sense, because SaveImageToDisk() uses a relative file path instead of an absolute file path.
-
And did you replace all the Form1-> with this-> ?
-
I have tried both suggestions, but that did not make any difference. The debugger again stops with a blue arrow at the loop line. If I press F8 to go to the next line of code - a blue arrow goes to the end of void __fastcall TForm1::FormCreate(TObject *Sender) - as before. Thx!
-
Remy, It works as it is, but I changed the code in the Client StringStream := TStringStream.Create(IdEncoderMIME1.Encode(MemoryStream),TEncoding.UTF8); .. IdTCPClient1.Socket.Write(JObj.ToJSON); I change the code in the Server code: StringStream := TStringStream.Create('', TEncoding.UTF8); I tried to use ReadString, but the I get a read error when it tries to parse the json PicStr: String; .. PicStr := AContext.Connection.IOHandler.ReadString(-1); JSON := TJSONObject.ParseJSONValue(PicStr) as TJSONObject; It works fine now and I found that it did save the images, but they was not in the folder that I had in the filename string, but in the project folder where the application was running from. I take a picture with the camera and place it in a TImage. procedure TMainForm.TakePhotoFromCameraAction1DidFinishTaking(Image: TBitmap); begin Image1.Bitmap.Assign(Image); end; Then with the same code that works sending a image from a file works. MemoryStream := TMemoryStream.Create; MemoryStream.Position := 0; MemoryStream.LoadFromFile(FImageFilePath); When I try this I get a blank image. MemoryStream := TMemoryStream.Create; MemoryStream.Position := 0; Image1.Bitmap.SaveToStream(MemoryStream); Thanks for your help.
-
Optimaster joined the community
-
I don't see how that is possible given the bugs I mentioned in the code you showed. Also, I just now noticed another bug I didn't see earlier - your server code is not synchronizing the call to SaveImageToDisk(). OK, but the rest of the server code you showed is still buggy. First off, you should not be calling TIdTCPClient.Connect() in the main UI thread. In fact, modern Android versions do not allow any network operations on the main thread at all. Second, that client send code does not match the server read code you showed earlier! Your client is sending the JSON using IOHandler.WriteLn(), but your server is reading the JSON using IOHandler.ReadStream(). That will not work! You need to use IOHandler.ReadLn() on the server side, eg: procedure TMainForm.SendPicture; var Host, Msg: string; Port: Integer; begin {$IFDEF MSWINDOWS} FImageFilePath := TPath.Combine(TPath.GetDocumentsPath, EditImage.Text); {$ENDIF} {$IFDEF ANDROID} FImageFilePath := TPath.Combine(TPath.GetSharedDocumentsPath, SetupForm.EditImage.Text); {$ENDIF} if not FileExists(FImageFilePath) then begin ShowMessage('No such file at ' + FImageFilePath + '!'); Exit; end; Host := SetupForm.EditHost.Text.Trim; if Host.IsEmpty then begin ShowMessage('Wrong host value!'); Exit; end; if not TryStrToInt(SetupForm.EditPort.Text, Port) then begin ShowMessage('Wrong port value!'); Exit; end; Msg := Edit1.Text; TTask.Run( procedure var MemoryStream: TMemoryStream; JObj: TJSONObject; JsonStr: string; begin try JObj := TJSONObject.Create; try MemoryStream := TMemoryStream.Create; try MemoryStream.LoadFromFile(FImageFilePath); JObj.AddPair('image_encoded', TIdEncoderMIME.EncodeStream(MemoryStream)); finally MemoryStream.Free; end; JObj.AddPair('message', Msg); JsonStr := JObj.ToJSON; finally JObj.Free; end; if IdTCPClient1.Connected then IdTCPClient1.Disconnect; IdTCPClient1.Host := Host; IdTCPClient1.Port := Port; try IdTCPClient1.Connect; except TThread.Queue(nil, procedure begin ShowMessage('Connection error!'); end); Exit; end; try try IdTCPClient1.IOHandler.WriteLn(JSonStr); finally IdTCPClient1.Disconnect; end; except TThread.Queue(nil, procedure begin ShowMessage('Send error!'); end); Exit; end; TThread.Queue(nil, procedure begin ShowMessage('BASE64 Image and message successfully sent to server!'); end); except on E: Exception do begin TThread.Queue(nil, procedure begin ShowMessage('Error! ' + E.Message); end); end; end; end); end; procedure TMainForm.IdTCPServer1Execute(AContext: TIdContext); var JSON: TJSONObject; MemoryStream: TMemoryStream; JsonStr, Msg: String; begin JsonStr := AContext.Connection.IOHandler.ReadLn; MemoryStream := nil; try JSON := TJSONObject.ParseJSONValue(JsonStr) as TJSONObject; try MemoryStream := TMemoryStream.Create; TIdDecoderMIME.DecodeStream(JSON.GetValue('image_encoded').Value, MemoryStream); Msg := JSON.GetValue('message').Value; finally JSON.Free; end; MemoryStream.Position := 0; TThread.Synchronize(nil, procedure begin Edit2.Text := Msg; Image1.Bitmap.LoadFromStream(MemoryStream); end); finally MemoryStream.Free; end; TThread.Synchronize(nil, SaveImageToDisk); end; However, if there is any possibility that the JSON may have any embedded line breaks, then using IOHandler.WriteLn/ReadLn will not work, so you should use IOHandler.Write(TStream) with IOHandler.ReadStream/ReadString() instead, eg: procedure TMainForm.SendPicture; var Host, Msg: string; Port: Integer; begin {$IFDEF MSWINDOWS} FImageFilePath := TPath.Combine(TPath.GetDocumentsPath, EditImage.Text); {$ENDIF} {$IFDEF ANDROID} FImageFilePath := TPath.Combine(TPath.GetSharedDocumentsPath, SetupForm.EditImage.Text); {$ENDIF} if not FileExists(FImageFilePath) then begin ShowMessage('No such file at ' + FImageFilePath + '!'); Exit; end; Host := SetupForm.EditHost.Text.Trim; if Host.IsEmpty then begin ShowMessage('Wrong host value!'); Exit; end; if not TryStrToInt(SetupForm.EditPort.Text, Port) then begin ShowMessage('Wrong port value!'); Exit; end; Msg := Edit1.Text; TTask.Run( procedure var MemoryStream: TMemoryStream; StringStream: TStringStream; JObj: TJSONObject; begin try StringStream := nil; try JObj := TJSONObject.Create; try MemoryStream := TMemoryStream.Create; try MemoryStream.LoadFromFile(FImageFilePath); JObj.AddPair('image_encoded', TIdEncoderMIME.EncodeStream(MemoryStream)); finally MemoryStream.Free; end; JObj.AddPair('message', Msg); StringStream := TStringStream.Create(JObj.ToJSON, TEncoding.UTF8); finally JObj.Free; end; if IdTCPClient1.Connected then IdTCPClient1.Disconnect; IdTCPClient1.Host := Host; IdTCPClient1.Port := Port; try IdTCPClient1.Connect; except TThread.Queue(nil, procedure begin ShowMessage('Connection error!'); end); Exit; end; try try IdTCPClient1.IOHandler.LargeStream := False; IdTCPClient1.IOHandler.Write(StringStream, 0, True); finally IdTCPClient1.Disconnect; end; except TThread.Queue(nil, procedure begin ShowMessage('Send error!'); end); Exit; end; finally StringStream.Free; end; TThread.Queue(nil, procedure begin ShowMessage('BASE64 Image and message successfully sent to server!'); end); except on E: Exception do begin TThread.Queue(nil, procedure begin ShowMessage('Error! ' + E.Message); end); end; end; end); end; procedure TMainForm.IdTCPServer1Execute(AContext: TIdContext); var JSON: TJSONObject; MemoryStream: TMemoryStream; StringStream: TStringStream; // alternatively: // JSONStr: string; Msg: String; begin MemoryStream := nil; try StringStream := TStringStream.Create('', TEncoding.UTF8); try AContext.Connection.IOHandler.LargeStream := False; AContext.Connection.IOHandler.ReadStream(StringStream, -1, False); JSON := TJSONObject.ParseJSONValue(StringStream.DataString) as TJSONObject; finally StringStream.Free; end; // alternatively: // JSONStr := AContext.Connection.IOHandler.ReadString(AContext.Connection.IOHandler.ReadInt32); // JSON := TJSONObject.ParseJSONValue(JSONStr) as TJSONObject; try MemoryStream := TMemoryStream.Create; TIdDecoderMIME.DecodeStream(JSON.GetValue('image_encoded').Value, MemoryStream); Msg := JSON.GetValue('message').Value; finally Json.Free; end; MemoryStream.Position := 0; TThread.Synchronize(nil, procedure begin Edit2.Text := Msg; Image1.Bitmap.LoadFromStream(MemoryStream); end); finally MemoryStream.Free; end; TThread.Synchronize(nil, SaveImageToDisk); end;
-
Sure but the fact that it's only available via WinRT sort of confirms that it isn't, doesn't it?
-
Remy, I do see the image in the TImage on the server application after it is send from the client app. I by accident remove the rest to 0, but still no file are saved. Here is the Client side running on Android. procedure TMainForm.SendPicture; var MemoryStream: TMemoryStream; StringStream: TStringStream; JObj: TJSONObject; begin {$IFDEF MSWINDOWS} FImageFilePath := TPath.Combine(TPath.GetDocumentsPath, EditImage.Text); {$ENDIF} {$IFDEF ANDROID} FImageFilePath := TPath.Combine(TPath.GetSharedDocumentsPath, SetupForm.EditImage.Text); {$ENDIF} if not FileExists(FImageFilePath) then begin ShowMessage('No such file at ' + FImageFilePath + '!'); Exit; end; IdTCPClient1.Host := SetupForm.EditHost.Text; try IdTCPClient1.Port := Integer.Parse(SetupForm.EditPort.Text); except on EConvertError do begin ShowMessage('Wrong port value!'); Exit; end; end; if not IdTCPClient1.Connected then begin try IdTCPClient1.Connect; except on EIdSocketError do begin ShowMessage('Connection error!'); Exit; end; end; end else begin IdTCPClient1.Disconnect; Exit; end; TTask.Run( procedure begin MemoryStream := nil; StringStream := nil; JObj := nil; try MemoryStream := TMemoryStream.Create; MemoryStream.LoadFromFile(FImageFilePath); StringStream := TStringStream.Create(IdEncoderMIME1.Encode(MemoryStream),TEncoding.ASCII); JOBJ := TJSONObject.Create; JOBJ.AddPair('image_encoded', StringStream.DataString); JOBJ.AddPair('message', Edit1.Text); IdTCPClient1.Socket.WriteLn(JObj.ToJSON); TThread.Synchronize(nil, procedure begin ShowMessage('BASE64 Image and message successfully sent to server!'); end); finally IdTCPClient1.Disconnect; JObj.Free; StringStream.Free; MemoryStream.Free; end; end); end; Right no I'm testing the send and save on the server side, but eventually I would like to send and save an image displayed in a TImage on the client side and not a file. The TImage is from the camera.
-
I update this topic 'cause new versions are released of Halcon (and quote Matthias that were interested about that). I post a Delphi wrapper around this, not a really Delphi wrapper, only a porting from C headers that I have done with CHET. Take care that some adjustments should be done from your previous sources because in Halcon are changed some records (Tuples), and for other reasons too. Read carefully the "Release Notes for HALCON 24.11.1.0 Progress-Steady" (https://www.mvtec.com/products/halcon/work-with-halcon/documentation/release-notes-2411-1) for full details. I tried the new wrapper only partially. Bye HalconC_2411.pas
-
Enumerating Windows clipboard history in C++/WinRT and C# Enumerating Windows clipboard history in PowerShell But, the way Microsoft describes this API, they make it sound like it is "the clipboard" history.
-
A clipboard history is a convenient way to see lots of passwords in plaintext. Who wouldn't love that.
-
How do I create/generate unique ID texts?
FPiette replied to JohnLM's topic in Algorithms, Data Structures and Class Design
Here an example: program Crcr32Demo; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, System.ZLib; var Buf1 : AnsiString; Buf2 : String; Crc : UInt32; begin Buf1 := 'Hello World!'; Crc := System.ZLib.Crc32(0, PByte(Buf1), Length(Buf1) * Sizeof(Buf1[1])); WriteLn('AnsiString ID=', IntToHex(Crc, 8)); Buf2 := 'Hello World!'; Crc := System.ZLib.Crc32(0, PByte(Buf2), Length(Buf2) * Sizeof(Buf2[1])); WriteLn('UnicodeString ID=', IntToHex(Crc, 8)); ReadLn; end. The output is: AnsiString ID=1C291CA3 UnicodeString ID=E2106423 AnsiString and Unicode string doesn't produce the same result because character code are different (8 bit and 16 bit per character). and CRC32 work at the byte level. -
True, the initial cost of Delphi is quite substantial, but the yearly renewals is something to live with, I know several tools that is more expensive and less capable...
-
The indication on the "GOTO" page is not precise, it was always like this.
-
I think it is saying 5 hours and some minutes. Does anyone else have trouble with GetIt servers today?
-
This has been resolved.
-
Validity Not After Thu, 21 Nov 2024 10:24:06 GMT Please renew certificate
-
Absolutely, that, to me, is one of the main point to go with Delphi or C++Builder. You have 1 codebase. Sure, you'll have conditional compile/code for specific platform, but still only 1 project. No need for 5 different sources/teams to maintain in parallel (it never works) for Windows, macOS, iOS, Android and Linux.
-
ICS 9.3 Memory leak THttpAppSrv.PutDispatchVirtualDocument()
Angus Robertson replied to YvesV's topic in ICS - Internet Component Suite
Thanks, fix will be added for the next release shortly. Angus -
How do I create/generate unique ID texts?
JohnLM replied to JohnLM's topic in Algorithms, Data Structures and Class Design
@FPiette I did consider your suggestion, but I could not understand it. I tried a second time after your last post and I still could not understand it, how to use it, etc. I think that "buf" is throwing me off. I'm not that good at pointers. I thought buf was an array and was to hold some bytes, so I tryined to move the string into it and, well, I just don't have the skills for this. I'm an amature programmer, and this is my hobby, and I'm not some wiz-kid know-it-all. So, I'm giving it up your suggestion per your link. its 5:32am and I work the night shift (truck unloading work) and I'm exhausted. However, I found another resource for crc32 and tried that, and it seems to be working. But again, I'm exhausted. I'll play around with it much later. I need sleep. -
Hi there, I'm quite confused on the starting time of the C++ Webinar today. It shows 10:00 CST in the EMail note, which should be 17:00 in Germany. ... But it also tells me when joining Goto: 5 hours to go .... This would be 16:00 in Germany. I actually believe the Goto schedules, which should be correct, but something seems weird here. 🤔
-
Don't forget the cost of maintaining two or more projects in more than one language, with more than one IDE / OS. Depending on the subject, the cost of Delphi licenses is not so high.
-
Great point, I did not really think about that. That also means increased costs, since I need to keep my Delphi current at all times 😓 Using the .Net universe will be the more cost friendly option to consider. But the point about keeping on top of new os versions apply there too... Hmm, not as straight forward choice as I thought 🤔
-
When it comes to mobile development you cannot count on that kind of stability. Not because of Delphi, but because of platforms. android and iOS get new OS version every year, often with drastic changes in some workflows and features. They also expect that you frequently update your application and make it compatible with new OS versions (old applications still run, but if you don't make an update in two years period applications will not be available to users with new OS versions - this is just example, there are variants of what exactly happens in each particular case). Those OS changes also require changes in Delphi toolset and sometimes additions in code. How drastic depends on the each particular change. This is valid for all mobile development toolsets, and is nothing Delphi specific. But, this also means that you will have to keep current with new Delphi releases and you cannot stick using some old Delphi version for too long after new one gets out.