TurboPack / Orpheus

Orpheus is an award-winning UI toolkit for Embarcadero Delphi & C++Builder
Other
99 stars 36 forks source link

OvcDbtbl table combobox painting raise AV #39

Open xCMNx opened 1 year ago

xCMNx commented 1 year ago

The problem could be that we allocate PString for TOvcTCComboBox data in tryGetMem, that is the first part of problem. In tryGetMem we need to check type of cell to use GetMem insteed New(PString), tryFreeMem need to fix too

  ///TOvcTCComboBox data is not just a PString
  if ((ACell is TOvcTCString) or (AField.DataType in [ftString, ftWideString])) and not (ACell is TOvcTCComboBox) then
    New(PString(P))
  else
    GetMem(P, Size);

The second part is tbGetFieldValue we use allocated PString like a TCellComboBoxInfo

     end else begin
        /// looks OK if we use new(PString) in tryGetMem
        PString(Data)^ := AField.Text;
        /// still OK
        if PString(Data)^ = '' then
          Idx := -1
        else
          Idx := TOvcTCComboBox(ACell).Items.IndexOf(PString(Data)^);

        /// we just damaged a string data, it stil not so critical
        PCellComboBoxInfo(Data)^.Index := Idx;

        if Idx = -1 then
          if TOvcTCComboBox(ACell).Style in [csDropDown, csSimple] then
            /// and now we try to store our damaged string into what?
            PCellComboBoxInfo(Data)^.St := PString(Data)^ //S;

It works if change it to

     end else begin
        if AField.Text = '' then
          Idx := -1
        else
          Idx := TOvcTCComboBox(ACell).Items.IndexOf(AField.Text);

        PCellComboBoxInfo(Data)^.Index := Idx;

        if Idx = -1 then
          if TOvcTCComboBox(ACell).Style in [csDropDown, csSimple] then
            PCellComboBoxInfo(Data)^.St := AField.Text;
romankassebaum commented 1 year ago

I hope that I understood you correctly. Please check.