Jump to content

Bart Verbakel

Members
  • Content Count

    24
  • Joined

  • Last visited

Everything posted by Bart Verbakel

  1. Hello all, I have a question, but i don't know exactly how to explain the problem... Is it possible to use "dynamic" control names to set their properties? For example: I have a form with 5 buttons (Button1, Button2...Button5) Instead of using following code: Button1.Enabled:=True Button2.Enabled:=True Button3Enabled:=True Button4.Enabled:=True Button5.Enabled:=True I want to use something like: for k:=1 to to 5 do (Edit-k-).enabled=True; I hope you understand my question :) With kind regards, Bart
  2. Bart Verbakel

    Use of dynamic control names

    No,these are not dynamic controls that are defined at runtime. Maybe I choosed the wrong words for this topic. The controls are defined at the design phase, I want to replace the "static" code Edit1.text:='ABCD' replaced by another code where the '1' is a variable. so I can use some code like: var sName:Array[1..10] of string for k:=1 to 10 do sName[k]:=Edit[k].text; I am now checking which solution mentioned above is the best for me
  3. Bart Verbakel

    Use of dynamic control names

    Thank you for al the replies. I have to do some more investigation to find out which solution is the best for me and write a simple application to check its behaviour. Bart
  4. Hello, I want to use bold text in specific listview cells, depending on the value in the cell, for example a bold font for all negative values. I can put bold text in a listview using the ListView1AdvancedCustomDrawSubItem event, but i that case I have to specify the row and column number in the eventcode. Since I do not know up front which values are negative, I cannot specify fixed row and column numbers in the code. I tried to solve it with a public variable 'BoldText', which is set to True if the text has to be bold. If value < 0 then BoldText:=True else Boldtext:=False; Listitem:=ListView1.Items.Add; ListItem.Subitems.Add(IntToStr(value)); .... procedure TForm8.ListView1AdvancedCustomDrawSubItem(Sender: TCustomListView; Item: TListItem; SubItem: Integer; State: TCustomDrawState; Stage: TCustomDrawStage; var DefaultDraw: Boolean); begin if BoldText then Sender.Canvas.Font.Style := [fsBold]; end; Unfortunately this does not work, all fonts are regular. However, when I use the code: procedure TForm8.ListView1AdvancedCustomDrawSubItem(Sender: TCustomListView; Item: TListItem; SubItem: Integer; State: TCustomDrawState; Stage: TCustomDrawStage; var DefaultDraw: Boolean); begin if (Item.Index=6) and (SubItem=8) then Sender.Canvas.Font.Style := [fsBold]; end; It works OK for cell (6,8) Does anybody have a solution? It looks like a simple problem, but I cannot figure out how to solve it. Thanks in advance, Bart
  5. Bart Verbakel

    Using bold text in Listview

    This code doesn't seem to work (for me) var li := ListItem1.Items.Add; I think you meant: var li:=Listview1.items.Add? li.Data := TListItemData.Create; Constructor Create needs a parent. Listview1, Self of nil does not work as a parent.
  6. Bart Verbakel

    Using bold text in Listview

    Ok, thank you for your reply. I will try if I can get it working like this. Bart
  7. Hello all, I want to change to color of a combobox, depending of the contents of it. If CB1 and CB2 contain the same value, the color of CB1 will be orange, if not the color will be default (ClWindow) procedure TForm1.ComboBox1Change(Sender: TObject); var ClOrange:ColorRef; begin ClOrange:=RGB(255,160,0); if Combobox1.Text=Combobox2.Text then Combobox1.Color:=ClOrange else Combobox1.Color:=ClWindow; end; This code works OK, but I got a warning during compling: W1071 Implicit integer cast with potential data loss from 'Cardinal' to 'TColor' It feels like my code is not 100% correct , but I don't understand the issue. I tried conversions to RGB or a StringToColor conversion, but all in vain, How can I prevent this hint from popping up (and not disabeling it in the options 😉 ) With kind regards, Bart
  8. Yes, that works ok for me. Thank you
  9. Hello, I am trying to convert a record to a JSON string, so I can save and load the data to a file. I have a record with several datatypes, but for some reason I am unable to write an array of integers to a JSON string. Al other datatypes (array of string and booleans) work ok. procedure TForm1.Button7Click(Sender: TObject); type TMyRecord=record Name:String; Int:Array[1..3] of integer; Str:Array[1..3] of string; end; var MyRecord:TMyRecord; var Serializer:TJsonSerializer; begin MyRecord.name:='Bart'; Myrecord.Int[1]:=9; Myrecord.Int[2]:=5; Myrecord.Int[3]:=23; Myrecord.Str[1]:='A'; Myrecord.Str[2]:='B'; Myrecord.Str[3]:='C'; Serializer:=TJsonSerializer.Create; Memo1.Lines.Clear; Memo1.Lines.Add(serializer.Serialize(MyRecord)); FreeAndNil(Serializer); end; The JSON output string is: {"Name":"Bart","Str":["A","B","C"],"Rain":false} Why am I missing the array 'Int' in this JSON string? I also tried to use a different datatype iso integers (Int64, double, byte, real), but this does not work either. With kind regards, Bart
  10. type TInt3Array = array[1..3] of Integer; This is so simple... For me both declarations are the same, so I never found this solution by myself. Thank you for the support. Bart
  11. Hello, I am working for 20 years on a Delphi application, just updating it every year to meet my requirements and remove bugs. I have been using Delphi 7 until now, but lately I tried to update 20 years of code to Delphi 11. Some code has to be changed, and I found a solution for this changes. But somehow I am struggling with W1057 Implicit string cast from 'ShortString' to 'string' warnings. I know, this are only warning and I can disable them in the compiler settings, but I prefer a better solution. The code: MessageDlg(F1Pool.Deelnemer[High(F1Pool.Deelnemer)].Teamnaam + 'succesfully added!',mtInformation,[mbOk],0); Where F1Pool.Deelnemer.Teamnaam is declared as String[100]; It works OK(without warnings) then I only use substring 'succesfully add',but when I combine a string from a record with a fixed string I got warning W1057. I tried to use stringconversions like String(F1Pool.Deelnemer[High(F1Pool.Deelnemer)].Teamnaam), but all in vain... What am I doing wrong? I used this code in Delphi 7 for years without warnings. Bart
  12. Bart Verbakel

    W1057 during D7 -> D11 conversion

    Yes, that is ok for me. Thank you. Bart
  13. Bart Verbakel

    W1057 during D7 -> D11 conversion

    Hello all, Another question... I want to include some error handling in case a JSON string does not match the data structure. I tried the following code: var Serializer:TJsonSerializer; var Person:TPerson; begin Serializer:=TJsonSerializer.create; try Person:=Serializer.Deserialize<TPerson>(JSON_inputstring); except Showmessage('Error in JSON string'); end; FreeAndNil(Serializer); end; For a correct JSON string, this code works OK, but this does not work in case the inputstring has an invalid format (eg. 'ABCD') How can I handle these kind of errors? Bart
  14. Bart Verbakel

    Disable code completion in Delphi 11

    Hello all, I just upgraded from delphi 7 to Delphi 11 and Delphi 11 has code completion build in its editor, I think it is quite annoying and I want to disable it. Google answers: From the Tools | Options | Editor Options | Code Insight menu, deselect the Auto complete check box under Code template completion. The problem is that I don't have a Code Insight option in Delphi. Do I have to install Code Insight or is this setting hidden elsewhere? Bart
  15. Bart Verbakel

    Disable code completion in Delphi 11

    Yes, thank you!
  16. Bart Verbakel

    W1057 during D7 -> D11 conversion

    I am now experimenting with JSON datafiles for a week now, and I think I get a better understanding of how JSON files work. It is quite simple, if you know the correct procedures for serialising/deserialising my records. I only should gain some confidence in the conversion... It took a while to find out that serialsing a record with String[x] does not work, properly but does not return in an error either. It simply does not serialise that variable, resulting in data loss. After changing my strings to a string without a predefined length everything is OK. Thanks for the help so far!
  17. Bart Verbakel

    W1057 during D7 -> D11 conversion

    I got compatibility warnings during installation, so I decided to use Windows 7. But I can try it on Windows 11.
  18. Bart Verbakel

    W1057 during D7 -> D11 conversion

    I don't HAVE to go to Delphi 11, but I have 2 reasons for making this choice: 1. Delphi 7 is not supported by Windows 11. I need an old laptop running in Windows 7 and Delhi 7 to write the application. 2. I want to learn and improve my Application, to give it a modern look and doný stick to 20 years old software if an update is available. If it is too difficult or time consuming I will stick to Delphi 7. But I will give it a try.
  19. Bart Verbakel

    W1057 during D7 -> D11 conversion

    No, every year I set up a F1 manager game, where competitors have to buy a F1 team and earn points and money. This application calculates all the points during the F1 season. It is modified year after year to suit the needs. But now I want to switch from D7 to D11. Bart
  20. Bart Verbakel

    W1057 during D7 -> D11 conversion

    Yes, I have to freedom to change the data structure. My first goal was to get the 20-year old source code working on D11 without any errors. That goal is already reached. Now I can focus on optimizing the source code to modern standards. I have to do some research to bridge this 20-year gap 😅 Bart
  21. Bart Verbakel

    W1057 during D7 -> D11 conversion

    It is a record, build up with various datatypes. (Limited) strings, integers, booleans and reals. So it is not a simple textfile Bart
  22. Bart Verbakel

    W1057 during D7 -> D11 conversion

    Ok, then I was wrong. I wil try to rewrite to code and avoid ShortString To be continued....
  23. Bart Verbakel

    W1057 during D7 -> D11 conversion

    " Why are you using shortstring? Even in D7 that was not recommended. " I have to save the data to an external file. What do you recommend in this case? I thought declaring a variable a String, it could take up (almost) unlimited space, so therefore it is not possbile to write it to a file Bart
  24. Bart Verbakel

    W1057 during D7 -> D11 conversion

    I am using ShortString because I have to save the data to an external file. I think (correct me if I am wrong) this is only possible with an ShortString.
×