Jump to content

Bart Verbakel

Members
  • Content Count

    24
  • Joined

  • Last visited

Community Reputation

3 Neutral

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. 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
  2. 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
  3. 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
  4. 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.
  5. 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
  6. 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
  7. Yes, that works ok for me. Thank you
  8. 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
  9. 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
  10. 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
  11. Bart Verbakel

    W1057 during D7 -> D11 conversion

    Yes, that is ok for me. Thank you. Bart
  12. 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
  13. Bart Verbakel

    Disable code completion in Delphi 11

    Yes, thank you!
  14. 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!
  15. 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
×