KimHJ
Members-
Content Count
34 -
Joined
-
Last visited
Community Reputation
3 NeutralTechnical Information
-
Delphi-Version
Delphi 12 Athens
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
-
Yes, it compiles and it prints. First It didn't print, but then I added the command Nextline(1) first and PrintText after then it printed. Now I just need to create the rest of the app. I'm working on two different apps at the same time as you can see on my posts, not getting enough sleep lately. Again, thanks for all your help.
-
I have this code where I send an jpg image with TidTCPClient to a TidTCPServer. On the Server side the image aperea in a TImage, but no file is created when I save it. I tried using .jpg as well I try to use the MemoryStream.SaveToFile. I look in many forums and it looks like the do the same thing, what is wrong with this code? Here is the server code. procedure TMainForm.IdTCPServer1Execute(AContext: TIdContext); var JSON: TJSONObject; StringStream: TStringStream; MemoryStream: TMemoryStream; begin MemoryStream := nil; StringStream := nil; JSON := nil; try StringStream := TStringStream.Create('', TEncoding.ASCII); AContext.Connection.IOHandler.LargeStream := True; AContext.Connection.IOHandler.ReadStream(StringStream, SizeOf(StringStream), True); JSON := TJSONObject.ParseJSONValue(StringStream.DataString) as TJSONObject; MemoryStream := TMemoryStream.Create; IdDecoderMIME1.DecodeStream(JSON.GetValue('image_encoded').Value, MemoryStream); TThread.Synchronize(nil, procedure begin Edit2.Text := ''; Edit2.Text := JSON.GetValue('message').Value; Image1.Bitmap.LoadFromStream(MemoryStream); end); finally MemoryStream.Free; StringStream.Free; JSON.Free; end; SaveImageToDisk; end; procedure TMainForm.SaveImageToDisk; var CsFilename: String; begin CsFilename := Edit2.Text + '.png'; Image1.Bitmap.SaveToFile(CsFilename); end;
-
Great, that did it.
-
Ok it works, just had to open the port in the firewall.
-
Sorry, I still have problems when compiling the new JavaInterfaces.pas I get those errors all the way down from JSrPrinter_10 [JavaSignature('com/sr/SrPrinter$10')] JSrPrinter_10 = interface(JRunnable) ['{A13C6C9C-B945-4438-A33F-1B4453FD0555}'] function _Getval$line: Integer; cdecl; //function needs result type. With a red line under the $ sign procedure run; cdecl; property val$line: Integer read _Getval$line; // property 'val' does not exsist in base class. With a red line under val($line), read and $ sign in Getval$text end; TJSrPrinter_10 = class(TJavaGenericImport<JSrPrinter_10Class, JSrPrinter_10>) end; Does it looks like Java2Op created some wrong classes? Is it something i can correct manually? Again, thanks for any help. JavaInterfaces.pas
-
Thanks a lot for your help, I would never had been able to find out this by my self. I was almost going back to Android Studio and make the app there.
-
No, that is the jar file they emailed me in the SDK, with the example. I just posted a bit of the sample, here is the SDK I was emailed. The SDK is 18mb here is my dropbox link. https://www.dropbox.com/scl/fi/0nw4mhyha0qx72m4dbgfn/Java-Printer-SDK.zip?rlkey=tcn49jv2vt4ofmg90xojnzun5&dl=0
-
I have used RestDebugger a lot, but I never tried to call a php script from it. I did find this https://www.linkedin.com/pulse/sending-data-between-embarcadero-delphi-fmx-apps-using-serge-pilko-lo06f/ I will try to if I can get it to work, my first try it timed out.
-
Thanks, It worked I don't get any errors. Now I just have to find out why it's not printing. When I look at the Android example code it looks like they jus send the command printText MainActivity.this.findViewById(R.id.test2).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { SrPrinter.getInstance(getApplicationContext()).printText(((EditText) findViewById(R.id.test1)).getText().toString()); } catch (Exception e) { e.printStackTrace(); } } }); Here are the the first part of the SrPrinter.class package com.sr; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.graphics.Bitmap; import android.os.IBinder; import android.os.RemoteException; import java.util.Deque; import java.util.concurrent.LinkedBlockingDeque; import recieptservice.com.recieptservice.PSAMCallback; import recieptservice.com.recieptservice.PrinterInterface; import recieptservice.com.recieptservice.PrinterInterface.Stub; public class SrPrinter { static SrPrinter srPrinter; static Deque<Runnable> deque; static volatile PrinterInterface printerInterface = null; static boolean reconnect = false; static ServiceConnection serviceConnection = new ServiceConnection() { public void onServiceConnected(ComponentName componentName, IBinder iBinder) { SrPrinter.printerInterface = Stub.asInterface(iBinder); synchronized(SrPrinter.deque) { while(SrPrinter.printerInterface != null && !SrPrinter.deque.isEmpty()) { ((Runnable)SrPrinter.deque.poll()).run(); } } } public void onServiceDisconnected(ComponentName componentName) { SrPrinter.printerInterface = null; SrPrinter.reconnect = true; } }; public SrPrinter() { } public static synchronized SrPrinter getInstance(Context context) { Intent intent; if (srPrinter != null) { if (reconnect) { intent = new Intent(); intent.setClassName("recieptservice.com.recieptservice", "recieptservice.com.recieptservice.service.PrinterService"); context.startService(intent); context.bindService(intent, serviceConnection, 1); reconnect = false; } return srPrinter; } else { srPrinter = new SrPrinter(); deque = new LinkedBlockingDeque(); intent = new Intent(); intent.setClassName("recieptservice.com.recieptservice", "recieptservice.com.recieptservice.service.PrinterService"); context.startService(intent); context.bindService(intent, serviceConnection, 1); return srPrinter; } }
-
I have attached it here. printer.jar
-
Now I get exception 6 in the create line. Do I call the wrong class? procedure TMainForm.PrintThis(MyPrint:String); var Myprinter: JPrinterInterface; begin MyPrinter := TJPrinterInterface.Create; MyPrinter.beginWork; MyPrinter.printText(StringToJString('This Is A Test')); MyPrinter.endWork; end; JavaInterfaces.pas
-
Ok, I will have to install PHP on the local computer where i have Apache running, then add it in the LoadModule. I found this script in w3schools.com that i will place in the folder, I change the max size from 50000 to 2000000. <?php $target_dir = "myfolder/"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); // Check if image file is a actual image or fake image if(isset($_POST["submit"])) { $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); if($check !== false) { echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { echo "File is not an image."; $uploadOk = 0; } } // Check if file already exists if (file_exists($target_file)) { echo "Sorry, file already exists."; $uploadOk = 0; } // Check file size if ($_FILES["fileToUpload"]["size"] > 2000000) { echo "Sorry, your file is too large."; $uploadOk = 0; } // Allow certain file formats if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) { echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { echo "The file ". htmlspecialchars( basename( $_FILES["fileToUpload"]["name"])). " has been uploaded."; } else { echo "Sorry, there was an error uploading your file."; } } ?> Now my question how to execute the php script from the Delphi Android app, again when I search I only see Indy examples, I don't know if Indy works on Android. Thanks.
-
I installed Apache and then in the conf/ httpd.conf then i sat the DocumentRoot "C:/myfolder" and <Directory "C:/myfolder" > , AllowOverride All. I can see the Directory from another computer using a web browser and I can open the existing files. My problem is I don't know if I'm using the right way to save the image, I have been searching, all the example is see is mostly programmers that want add other thing to the files or they are using Indy.
-
I was to quick in saying that I had it. Loading an image a display it is working. I'm doing something wrong when I save, if I add a name to the URL like url := 'http://192.168.1.150/test1234.png' I get an error that path is not found. If I create a png file in the folder with that name I get no errors, but the image is not updated. I assume I have to name the Image first and the save it, but I don't see any option in TImage to assign a name to the bitmap, the image comes from the camera. Here is my code. procedure TMainForm.SaveImageToURL(const S: String); var ms : TMemoryStream; httpCli : TNetHTTPClient; resp : IHTTPResponse; url : String; Image: TBitmap; begin httpCli := TNetHTTPClient.Create(nil); try httpCli.UserAgent := 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0'; ms := TMemoryStream.Create(); try url := 'http://192.168.1.151/Test1234.png'; Image := TBitmap.Create; try ms.Seek(0,0); Image := Image1.Bitmap; Image.SaveToStream(ms); finally Image.Free; end; resp := httpCli.Post(url, ms); if resp.StatusCode <> 200 then Showmessage(Format('HTTP Error=%d %s', [resp.StatusCode, resp.StatusText])) finally ms.Free; end; finally httpCli.Free; end; end;
-
I got it to work with Apache. I had to add android:usesCleartextTraffic="true" in the manifest to be able to save and load with http, since the local machine don't have a SSL.