Forum > General

using stdconvs,convutils units in convertor demo

(1/1)

alaa123456789:
hi all ,

i am trying to make a demo for units convertor using the above mentioned units in uses section
after long research i reached to some knowledge about it (here incomplete code)

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, StdConvs, ConvUtils, Forms, Controls, Graphics, Dialogs,  StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    ComboBox1: TComboBox;    ListBox1: TListBox;     procedure ComboBox1Change(Sender: TObject);    procedure FormCreate(Sender: TObject);    procedure changefamily(Sender: TObject);  private    fam: TConvFamily;    fams: TConvFamilyArray;  public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);var   len: integer; begin  GetConvFamilies(fams);  Len := Length(Fams);  if (Len <> 0) then     for len := Low(Fams) to High(Fams) do      //ComboBox1.Items.Add(format('%d: %s',[ord(fam),ConvFamilyToDescription(fam)]));      ComboBox1.Items.Add(format('%s', [ConvFamilyToDescription(len)]));  ComboBox1.ItemIndex := 0;  changefamily(self);end; procedure TForm1.ComboBox1Change(Sender: TObject);begin  changefamily(self);end;   procedure TForm1.changefamily(Sender: TObject);var  atypes: TConvTypeArray;  i: integer;begin  //fggf  ListBox1.Clear;  fam := fams[ComboBox1.ItemIndex];  GetConvTypes(fam, atypes);  for i := Low(atypes) to High(atypes) do    ListBox1.Items.Add(format('%s', [ConvTypeToDescription(i)])); end; end.  but the results in the listbox are not correct (attched png)
what is wrong with it , here i attached also the demo project
please advise how to make it correct
thanks

wp:
Rather than

--- Quote from: alaa123456789 on July 08, 2022, 10:01:13 pm ---
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.changefamily(Sender: TObject);...  for i := Low(atypes) to High(atypes) do    ListBox1.Items.Add(format('%s', [ConvTypeToDescription(i)]));
--- End quote ---
use

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  for i in atypes do    ListBox1.Items.Add(ConvTypeToDescription(i)); This is because atypes is a TConvTypeArray which is nothing else than an array of integer. And Low() always returns 0 for a dynamic array. A bit strange kind of programming style was inherited from Delphi here...

BTW, there have been many changes recently in the conversion units, e.g. https://gitlab.com/freepascal.org/fpc/source/-/issues/39801, https://gitlab.com/freepascal.org/fpc/source/-/issues/39778, etc.

marcov:

--- Quote from: wp on July 08, 2022, 10:44:27 pm ---
BTW, there have been many changes recently in the conversion units, e.g. https://gitlab.com/freepascal.org/fpc/source/-/issues/39801, https://gitlab.com/freepascal.org/fpc/source/-/issues/39778, etc.

--- End quote ---

http://www.stack.nl/~marcov/mergelogs32/convutils.html

alaa123456789:

--- Quote from: wp on July 08, 2022, 10:44:27 pm ---
This is because atypes is a TConvTypeArray which is nothing else than an array of integer. And Low() always returns 0 for a dynamic array. A bit strange kind of programming style was inherited from Delphi here...



--- End quote ---

thanks WP , for all people in this forum
please watch and download the full sample from here

https://youtu.be/ZBV_ijOoG7k

Navigation

[0] Message Index

Go to full version