Hi , while I am waiting my other parts to arrive I decided to make some Arduino Control Panel in Delphi.
I am sending some info from my sensors to delphi application and I am reading that info with help of ComPort library.
Everything is good , and behind the scenes ComPort library converts output from Arduino app to String.
In my arduino shield i have few sensors , I am sending data from those sensors to app and than making some delay. It is in this format:
PHP Code
<?php Serial.write(temperature + "**" + humidity + "**" + amountOfLight ... etc... ); delay(2000);
This code works perfectly fine, and I am getting whole data that is displayed in this format, for example: 25 6415
In my delphi app i want to display this infos in separate labels . So basically I need to split this data and put it in some variables and after that update labels in delphi app.
Problem that I am facing is that i cannot take two first chars from this string ( 25 ) and display them because what if temperature is 5? In that case i will take "5*" and everything after that will be messed up.
So i need to find a way to get chunks of data between " ", is there any build in method that can help me ?
NOTE: I can format my data in different ways example: 24/52/15 or 42++15++125 .. it does not matter. ***********
Next question is about mysqli that i am using in my project.
I am making desktop app that will have embedded database , app is made with firemonkey so it is multi Device ( multi OS ) app.
When user open app for the first time , i want to make empty database called "test.db" for example. Next time when user opens the app i will check if that DB exist , and if that is true I will not make DB again.
Questions: Because it is multi OS app it can run on win,mas,andriod even watches. Where is best way to store this "test.db" file? Where should i store this file if it is win,mac,android or any other OS ? Is there any recommendations ? And should I use inside my app something called "Conditional compilation (Delphi)" ---> http://docwiki.embarcadero.com/RADStudio...n_(Delphi)
Second question: On the internet I found like 10 different DB delphi tutorials. Every tutorial is different and use different methods when performing CRUD operations, after whole day of searching I found some tut that works for me with insert statement, example:
PHP Code
<?php sSQL := 'INSERT INTO stats (field1, field2, field3, field4, field5, field6)values(777, 777, 777, 777, 777, 777);'; SQLQuery1.SQL.Text := sSQL; SQLQuery1.ExecSQL();
This 3 lines of code works for me , problem is that i tried 10 other tutorials that are not working for me , all of them use different functions/methods. So even that i got it working i am not sure that i am doing it on the right way if u know what I mean.
I tried to find info in official documentation but i just cant find it ... So can somebody give me link or explain me the right way of performing CRUD operations ?
*************
Another question: When user click to close app, before closing it i want to check for app width and height and app positioning on screen. I want to save this info and next time when user open app i want to display app with same size and position from the last time.
Question: Where should I store this parameters ( app width,height and position )? Should I store them in registry ?
***********
This question is about skins in my app. My app will have 2 skins , light and dark. I am using https://i.imgur.com/Ww2Dm7N.png this bitmap editor to load my FULL template and after that I plan to cut parts of template for buttons, text boxes etc... I think that it is right way to do it but I am not sure , so is this right way to do it?
Also , in my app i have some parts that are loading some images that are there just to make app look more pretty, example: https://i.imgur.com/k4XJM6q.png
As u see in this image i used Timage to display this white and blue icons with lines. Problem is that if user click dark skin from example I cant load different color of this image because it is not on my template.I can insert this whole picture and many others on my template but i dont think that it is right way to do it so maybe you can help me and tell me what is right way to handle this type of "decorations" in my app.. If i put them on my tamplate how should I define them , they are not buttons or any other component they are there just for decoration.
Thank you for your answers and sorry for long message 👍
Proud to be 100.000 user on HF
I have to say that I finally managed to make styles and custom styles that i want , so I solved that problem by my self.
If anyone other have problem I encourage them to take a look into Samples->Object Pascal->Multi-Device Samples->User Interface
There are plenty applications that you can learn of. Those Samples really helped me to understand how Styles work I was so stupid because I haven't look at them right away because i thought that those are some boring low level samples and demo apps but I was wrong. You can find there literally anything
Proud to be 100.000 user on HF
https://youtu.be/_okjwXswqKY
I found this video. This is answer to my first question
Proud to be 100.000 user on HF
another idea, a poor but easy way to do this is to assign each variable their own seperate hidden textbox and than just display their textbox without having to do dynamic char/string vars, this way can be done in 2 minutes, part of the 'ghetto mans debugger' solution (although it does allow easy postprocessing if needed), delphi console apps are hard to work with when they get very powerful becuz on old compilers the conversion of text/int/char/type array (etc) get very difficult and its just the way delphi is made..
Code //example
finaltext := (edit1.text + (strtoint(edit2.text));
not a single person has the time for that scenario
(Feb 17, 2019 02:58 AM)Joseph Ducreux Wrote: another idea, a poor but easy way to do this is to assign each variable their own seperate hidden textbox and than just display their textbox without having to do dynamic char/string vars, this way can be done in 2 minutes, part of the 'ghetto mans debugger' solution (although it does allow easy postprocessing if needed), delphi console apps are hard to work with when they get very powerful becuz on old compilers the conversion of text/int/char/type array (etc) get very difficult and its just the way delphi is made..
Code //example
finaltext := (edit1.text + (strtoint(edit2.text));
I think we misunderstood each other .. I can send only one line of info to Delphi program and it can be in any format. After that I need to extract some data from that big string.. Anyway, if I find answers to my other questions I will post it here so maybe someone will use it if they need it..
This is also answer for one of my questions :
https://www.thoughtco.com/working-with-w...ry-1058474
Proud to be 100.000 user on HF
Feb 17, 2019 08:29 AM
(This post was last modified: Feb 17, 2019 08:30 AM by tcsh.)
(Feb 11, 2019 03:48 PM)gua Wrote: Questions: Because it is multi OS app it can run on win,mas,andriod even watches. Where is best way to store this "test.db" file? Where should i store this file if it is win,mac,android or any other OS ? Is there any recommendations ?
Store it in your app local folder - where the app is/will be. Safest way when dealing with multiOS.
Quote: And should I use inside my app something called "Conditional compilation (Delphi)" ---> http://docwiki.embarcadero.com/RADStudio...n_(Delphi)
Haven't used it so far but it seems like an idea. Depends on your specifics :)
Quote:Second question: On the internet I found like 10 different DB delphi tutorials. Every tutorial is different and use different methods when performing CRUD operations, after whole day of searching I found some tut that works for me with insert statement, example:
PHP Code
<?php sSQL := 'INSERT INTO stats (field1, field2, field3, field4, field5, field6)values(777, 777, 777, 777, 777, 777);'; SQLQuery1.SQL.Text := sSQL; SQLQuery1.ExecSQL();
This 3 lines of code works for me , problem is that i tried 10 other tutorials that are not working for me , all of them use different functions/methods. So even that i got it working i am not sure that i am doing it on the right way if u know what I mean.
That's a valid sql insert statement, yes.
You can also use parameters / TSQL component and so forth. You're loading the statement into a variable, that's one way to go.
The other is by using an SQL component.
Example:
SQLQuery1.SQL.ADD('INSERT INTO stats (field1, field2, field3) VALUES (:field1, :field2, :field3)');
SQLQuery1.Params.ParambyName('field1').AsString := 'somevaluehere';
SQLQuery1.Params.ParambyName('field2').AsString := Edit1.Text;
SQLQuery1.Params.ParambyName('field3').AsString := alotofotherwaystodoit;
SQLQuery1.ExecSQL();
Quote:I tried to find info in official documentation but i just cant find it ... So can somebody give me link or explain me the right way of performing CRUD operations ?
https://github.com/anderson-81/crud-delphi--mysql
http://delphiexamples.com/databases/simplesql.html
https://mikejustin.wordpress.com/2014/02...th-delphi/
https://www.google.com/search?q=delphi+c...e&ie=UTF-8
Lots of examples out there. Refine your google keyword search.
Quote:Another question: When user click to close app, before closing it i want to check for app width and height and app positioning on screen. I want to save this info and next time when user open app i want to display app with same size and position from the last time.
Question: Where should I store this parameters ( app width,height and position )? Should I store them in registry ?
I've had to do this for a desktop app that contains several DBGrids. I wanted to save and load the w/h of the grids columns.
This is how I did it.
Code //Form2, in this case, is the main form. So when that's created (app opened) I load the previously saved settings from the .ini into the DBGrid. The .ini files are saved in the app folder. Next to the .exe
procedure TForm2.FormCreate(Sender: TObject);
begin
DBGrid1.Columns.LoadFromFile('DBGrid1.ini');
DBGrid2.Columns.LoadFromFile('DBGrid2.ini');
DBGrid3.Columns.LoadFromFile('DBGrid3.ini');
DBGrid4.Columns.LoadFromFile('DBGrid4.ini');
end;
Code //This is how I save the last settings (w/h) of the DBGrids columns when the user closes the app. Remember, TForm2 is the main app form and the DBGrids are on it.
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
DBGrid1.Columns.SaveToFile('DBGrid1.ini');
DBGrid2.Columns.SaveToFile('DBGrid2.ini');
DBGrid3.Columns.SaveToFile('DBGrid3.ini');
DBGrid4.Columns.SaveToFile('DBGrid4.ini');
application.Terminate;
end;
Basically, I save everything related to the DBGrid columns when I close the app and then load everything when I open the app. Easy.
You just use Save and Load from file to save your specific needs.
You need to store (SaveToFile) the parameters you want, then load and assign them to your app at runtime (using LoadFromFile, reading from the .ini/.txt/.whatever)
🤝
"Store it in your app local folder - where the app is/will be. Safest way when dealing with multiOS."
Yeah but I wanted kinda "professional way" of doing this that is why I asked but ok nvm thank you for response :D
yeah , this delphi sql stuff and binding to variables is to prevent sql injection or something , i guess it is similar like using PHP . thanks for the links ..
I will take a look into ini , thanks for that..
While we are here let me ask you something .. I am building arduino control panel app ( in delphi ) to control arduino ..
Let for example i have list of options in string grid. they are listed like "LED, Temperatyre sensor , light sensor .. etc.."
when user click on "LeD" for example , i am grabbing index from that string grid and using if statements i am comparing number in order to create other custom settings in runtime.
Custom settings are : setting pin , displaying buttons for on/off led , showing pictures how led light looks like and showing diagram picture how to connect leds to arduino. , after that i will provide code for user to upload to his arduino and after that he can monitor and send commands to his arduino ( turn on/off led for example ) .
As you see there a lot of stuff going on in runtime just for simple Led program example.
Imagine that I have a lot more arduino components for user to choose. There can be a lot of combinations even for 5-6 sensors. And code is getting really big , My questions is, should I use separate classes for creating "settings on runtime" or should i make some default ini config files for every option ? Also one more question should I IMPORT all pictures in program ( there will be a lot of HQ resolution pictures ) or should I put them in separate "resources" folder and call them when needed ? I think app speed will be better if i not load all pictures in app.
Anyway my conclusion is that this type of app should be made on different way, i should make installer or something and install it like normal program and than have resources folders that will provide settings and images for anything that user choose , but it is too hard task for me and i dont know how to achieve that..
Also one more question , that I god on my mind today while I was in school.
Is delphi good for android programming ? I mean what is benefit of using delphi over the normal android studio in terms of speed of application ? Will android app made in delphi be slower than if u make similar app in android studio ? I guess it will .. obviously i can and i will try to google this android related stuff over the internet but i would like to hear your opinion because i enjoy talking to you :D sorry if i am boring xd and thanks
Proud to be 100.000 user on HF
(Feb 18, 2019 01:47 PM)gua Wrote: "Store it in your app local folder - where the app is/will be. Safest way when dealing with multiOS."
Yeah but I wanted kinda "professional way" of doing this that is why I asked but ok nvm thank you for response :D
What exactly is unprofessional with this method? It's extremely common and most definitely professional.
Sure, you could store it in the registry or any other place - that's a choice.
Quote:yeah , this delphi sql stuff and binding to variables is to prevent sql injection or something , i guess it is similar like using PHP . thanks for the links ..
Precisely, prevents sql injection. Its a good coding habbit to pick up early on.
As well as making your code more organized.
Quote:I will take a look into ini , thanks for that..
saving in a .ini is just a coding habbit/example. You can use a lot others. Most common though is .ini
Good luck
Quote:While we are here let me ask you something .. I am building arduino control panel app ( in delphi ) to control arduino ..
Let for example i have list of options in string grid. they are listed like "LED, Temperatyre sensor , light sensor .. etc.."
when user click on "LeD" for example , i am grabbing index from that string grid and using if statements i am comparing number in order to create other custom settings in runtime.
Custom settings are : setting pin , displaying buttons for on/off led , showing pictures how led light looks like and showing diagram picture how to connect leds to arduino. , after that i will provide code for user to upload to his arduino and after that he can monitor and send commands to his arduino ( turn on/off led for example ) .
As you see there a lot of stuff going on in runtime just for simple Led program example.
Imagine that I have a lot more arduino components for user to choose. There can be a lot of combinations even for 5-6 sensors. And code is getting really big , My questions is, should I use separate classes for creating "settings on runtime" or should i make some default ini config files for every option ?
Personally, I'd go with separate default .ini config files for every option. Seems more organized.
Quote:Also one more question should I IMPORT all pictures in program ( there will be a lot of HQ resolution pictures ) or should I put them in separate "resources" folder and call them when needed ? I think app speed will be better if i not load all pictures in app.
Separate res and call when using. Best approach for performance. It will hang and lag somewhat if you load them all at once.
Quote:Anyway my conclusion is that this type of app should be made on different way, i should make installer or something and install it like normal program and than have resources folders that will provide settings and images for anything that user choose , but it is too hard task for me and i dont know how to achieve that..
Its a massive task to create an installer & updater for software, it involves having the resources ready on a server, pushing them and so forth. Its definitely worth it though, a really nice learning curve and you get to experience a lot of things. I'd definitely recommend trying to build one of these yourself when you have the right projet. This might not be it.
However, until then, you can try ready make solutions for creating installers and updaters.
One that comes to mind is: Advanced Installer - currently at version 15.7 - it even has specific imports for delphi project, right from the studio ;)
I've sent you a link in PM. Check it out.
Quote:Also one more question , that I god on my mind today while I was in school.
Is delphi good for android programming ? I mean what is benefit of using delphi over the normal android studio in terms of speed of application ? Will android app made in delphi be slower than if u make similar app in android studio ? I guess it will .. obviously i can and i will try to google this android related stuff over the internet but i would like to hear your opinion because i enjoy talking to you :D sorry if i am boring xd and thanks
Not boring at all, chill.
There is no difference, other than the quality of your code and logic. Personally I find the delphi rad studio more than sufficient for developing android apps and they are heavily focused on the multi app thing. You can bang out apps for android really fast with a lot less coding required. Since you're using delphi so much, I'd suggest using the rad studio also for android developments, as opposed to trying android studio or others. Ultimately, its your choice.
Only problem I can think of might be the fact that they may issue support for latest sku somewhat late. If I remember correctly (i dont code android that much) they just barely released android 64bit / 26 support with Delphi 10.3 Rio so you would need the latest version of delphi for the latest android support. For your app to function on the latest android release. Other than that, can't think of any issues.
Do you guys have any clue how to send code to arduino and save/execute it on arduino .. basically i want to upload code from my delphi program to arduino. That is only step that i need to know before I release first version of this arduino control panel program. it will be open source on github..
I am using comport library for talking to arduino over usb
Proud to be 100.000 user on HF
(Mar 3, 2019 02:09 AM)gua Wrote: Do you guys have any clue how to send code to arduino and save/execute it on arduino .. basically i want to upload code from my delphi program to arduino. That is only step that i need to know before I release first version of this arduino control panel program. it will be open source on github..
I am using comport library for talking to arduino over usb
https://forum.arduino.cc/index.php?topic=490338.0
http://www.vwlowen.co.uk/arduino/usb-dig...ontrol.htm
https://playground.arduino.cc/Interfacing/Delphi
http://delpres.blogspot.com/2014/02/delp...duino.html
google search: delphi code to arduino
...and similar searches. lots of info out there.
I haven't used delphi code to arduino so no clue further.
Also, try to open new threads here in this section for specific, different, questions.
Much more organized for everyone than just using a single thread.
🤝
Mar 3, 2019 08:39 AM
(This post was last modified: Mar 3, 2019 08:40 AM by gua.)
(Mar 3, 2019 02:37 AM)tcsh Wrote: https://forum.arduino.cc/index.php?topic=490338.0
http://www.vwlowen.co.uk/arduino/usb-dig...ontrol.htm
https://playground.arduino.cc/Interfacing/Delphi
http://delpres.blogspot.com/2014/02/delp...duino.html
google search: delphi code to arduino
...and similar searches. lots of info out there.
I haven't used delphi code to arduino so no clue further.
Also, try to open new threads here in this section for specific, different, questions.
Much more organized for everyone than just using a single thread.
🤝
Yeah, I already saw this and I made much more complicated app in deplhi to control arduino ( send and receive"commands") the only problem is that i dont know how to upload code and save it on arduino over delphi desktop app.. I will to bigger research if i find answer i will post it here , anyway thank you for posting 👍
Proud to be 100.000 user on HF
|