Recent

Author Topic: programming with Lazarus  (Read 1289 times)

srvaldez

  • Jr. Member
  • **
  • Posts: 55
programming with Lazarus
« on: September 11, 2024, 06:33:23 pm »
I worked in the oilfield industry, the business that I worked at specialized in making weighed fluids to be used for well control when work needed to be done on the well
my programmable calculator made the simple but tedious calculations easy, but just for fun I wanted to program a very simple fluid calculator in Lazarus which I did
revisiting the project made me wonder where I got the info on detecting keystrokes and modify it's behavior, for example, for ease of navigating the 4 text boxes I wanted the return key to behave as the tab key and shift-return as shift-tab
how do you Lazarus programmers program the behavior of the different graphical elements ?
it took me a week to search and piece together a very simple calculator, how do you guys do it ?
for anyone interested here's the source of my calculator https://u.pcloud.link/publink/show?code=XZzuzU0ZhwcAQuFzWEQHtjduxqOCukH4e39V

MarkMLl

  • Hero Member
  • *****
  • Posts: 7699
Re: programming with Lazarus
« Reply #1 on: September 11, 2024, 07:07:51 pm »
I'm by no means the most skilled at this around here, so please consider this a placeholder until somebody who knows what he's talking about comes along :-)

By and large, if I do have to do something non-standard (e.g. a terminal emulator which can handle weird key-combinations and weirder character sets :-), I start with the key-up event of the control of interest. For something like moving between fields- if this is really not supported by the controls themselves- you might (lots of handwaving here- sorry) have to work further up the list of containing controls.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

iLya2IK

  • New Member
  • *
  • Posts: 45
Re: programming with Lazarus
« Reply #2 on: September 12, 2024, 06:51:13 am »
Try using the TStringGrid element with the custom OnDrawCell method and configure it using the Columns property (to set the read-only property for the desired cells)

kupferstecher

  • Hero Member
  • *****
  • Posts: 590
Re: programming with Lazarus
« Reply #3 on: September 12, 2024, 11:53:45 am »
for anyone interested here's the source of my calculator
A screenshot would be nice.

Aruna

  • Sr. Member
  • ****
  • Posts: 458
Re: programming with Lazarus
« Reply #4 on: September 12, 2024, 12:11:32 pm »
for anyone interested here's the source of my calculator
A screenshot would be nice.
Here you go :-)
Debian GNU/Linux 11 (bullseye)
https://pascal.chat/

wp

  • Hero Member
  • *****
  • Posts: 12366
Re: programming with Lazarus
« Reply #5 on: September 12, 2024, 01:13:52 pm »
how do you guys do it ?
Basically, in the same way, maybe I reuse some event handlers for multiple controls. For a more specific answer I'd ask you to tell us typical input parameters for the Edit controls so that I can better test your applicaton.

BTW, you can also attach source code directly to your forum message ("Attachments and other options"). This has the advantage that it remains an integral part of the message - on a third-party cloud server it may disappear at any time.

MarkMLl

  • Hero Member
  • *****
  • Posts: 7699
Re: programming with Lazarus
« Reply #6 on: September 12, 2024, 01:45:16 pm »
Of course an interesting subsidiary question is what the original calculator was i.e. how the most comfortable UI would behave.

I've got a vision of its being one of the fancy HP desktop engineering systems i.e. HP-85 or similar, for which somebody might even have written an emulator...

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

VisualLab

  • Sr. Member
  • ****
  • Posts: 492
Re: programming with Lazarus
« Reply #7 on: September 12, 2024, 03:36:59 pm »
for anyone interested here's the source of my calculator

What is this parameter that is not described? (it is located at the top of the 2nd column, it has no label, I marked it in the screenshot)



EDIT: OK. I found the answer in the source code (i.e. the parameter may be different depending on the selected radio button option).

I also had some observations. I would change the names of the controls (labels, edit fields, buttons and radio buttons) and variables to more descriptive ones. The numbers do not say anything (e.g.: Edit1, good practice says that the code should be self-describing, e.g.: EditLightWeight). In addition, the name of the main window (TMudCalc) could also be more intuitive (e.g. TMudCalcForm, or even better, simply TMainForm).

The code contains these instructions like:

Code: Pascal  [Select][+][-]
  1. if RadioButton2.Checked = True
  2. then

You do not need to compare the control state with a boolean value. Just:

Code: Pascal  [Select][+][-]
  1. if RadioButton2.Checked
  2. then

There are also some repetitive texts. You can simplify the code by using text constants, e.g.:

Code: Pascal  [Select][+][-]
  1. SLabelCarbonate = 'Carbonate';

The code in the OnKeyDown event handler of several edit fields is also copied multiple times. You can create one procedure, which will then be assigned to the events of many controls (edit fields).

The code that zeros (empty string) the text of 4 text fields can also be simplified by creating a procedure that iterates over the edit fields and assigns them an empty string. This procedure would then be called when you need to zero the edit fields.
« Last Edit: September 12, 2024, 04:18:33 pm by VisualLab »

srvaldez

  • Jr. Member
  • **
  • Posts: 55
Re: programming with Lazarus
« Reply #8 on: September 12, 2024, 04:03:11 pm »
the top right parameter is either Carbonate if Heavy Weight is 22.5 or Densimix if Heavy Weight is between 41 and 42 inclusive, otherwise it's blank
but it won't show until you hit Calculate, try the following values on the left
Light Weight: 10
Heavy Weight: 22.5 or 41
Desired Weight: 14
Light Volume: 100
« Last Edit: September 12, 2024, 04:07:04 pm by srvaldez »

Ally

  • Jr. Member
  • **
  • Posts: 57
Re: programming with Lazarus
« Reply #9 on: September 13, 2024, 05:10:17 pm »
The Online Package Manager contains the rhsPack package with the DecimalNumberEdit component.
This makes it very easy to enter and evaluate numbers.

Here is the description:

DecimalNumberEdit is a component for entering numbers. The input field only accepts valid numbers that can be limited using the Matrix property. The component provides four new properties.

1. Matrix (string)
   The number format is defined via this property.

   Examples:
   99.99 Allows you to enter values in the range from 0 to 99.99 with two decimal places.
   -50.9 Allows you to enter values in the range from -50.9 to 50.9 with one decimal place.
   250.000 Allows you to enter values in the range from 0 to 250 with three decimal places.
   -500 Allows you to enter values in the range from -500 to 500 without decimal places.

2. Value (Extended)
   Returns the extended value of the entered value.
   This value can be evaluated during input and represents the value currently entered in the input field.

3. EnterKey (Boolean)
   Allows the Enter key to be used in the same way as the Tab key.

4. WarningTone (Boolean)
   Outputs a warning tone when illegal entries are made.



Here is your program, adapted for DecimalNumberEdit.

Josh

  • Hero Member
  • *****
  • Posts: 1324
Re: programming with Lazarus
« Reply #10 on: September 13, 2024, 07:41:01 pm »
Hi
Had a quick play.
Did a fair amount of  re-jigging; so need to check the calculations.
Controls named to something of meaning,.
Enter Navigation between fields.
Tedit expects decimal,
Some basic error checking/ math div by zerochecks etc.
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

srvaldez

  • Jr. Member
  • **
  • Posts: 55
Re: programming with Lazarus
« Reply #11 on: September 13, 2024, 08:33:55 pm »
thank you Josh  for sharing, it looks cool :)

VisualLab

  • Sr. Member
  • ****
  • Posts: 492
Re: programming with Lazarus
« Reply #12 on: September 14, 2024, 01:17:44 pm »
Hi
Had a quick play.
Did a fair amount of  re-jigging; so need to check the calculations.
Controls named to something of meaning,.
Enter Navigation between fields.
Tedit expects decimal,
Some basic error checking/ math div by zerochecks etc.

I would see two more possibilities for improvement: a label for the frame with 3 radio buttons (maybe: TRadioGroup, which has a built-in label) and numeric edit fields (e.g. TFloatSpinEdit, which is available in the standard Lazarus palette). These are not key improvements, but they will slightly improve the user's perception of the calculator.

 

TinyPortal © 2005-2018