Page 1 of 1

DataSet Refresh Breaks

Posted: Wed 20 Nov 2013 19:49
by MilanLepi
Hello everyone,

I use Delphi 2010 and I'm connecting to MS SQL Server 2008.

My UniDataSource1.DataSet.Refresh breaks in one case, I put the code here (small project)
http://www.filedropper.com/servertest
When you try to compile it - it will lead you to the error line.

I would be happy if someone can explain me why it breaks and what to do to solve it.

Thanks

Re: DataSet Refresh Breaks

Posted: Thu 21 Nov 2013 11:57
by AndreyZ
Hello,

In your example, you are working with memory incorrectly, which leads to erasing memory that you did not allocate. To avoid the problem, you should rewrite your GetDateTimePickerText function as follows:

Code: Select all

function GetDateTimePickerText(const DateTimePicker : TDateTimePicker) : String;
// http://docwiki.embarcadero.com/CodeExamples/XE3/en/GetTextBuf_%28Delphi%29
var SizeInt : Integer;
    BufferPWideChar : PWideChar;
begin
  SizeInt := DateTimePicker.GetTextLen();             {Get length of string in DateTimePicker}
  Inc(SizeInt);                                       {Add room for null character}
  SizeInt := SizeInt * SizeOf(Char); // THIS code is added
  GetMem(BufferPWideChar, SizeInt);                   {Creates Buffer dynamic variable}
  DateTimePicker.GetTextBuf(BufferPWideChar,SizeInt); {Puts DateTimePicker.Text into Buffer}
  Result := StrPas(BufferPWideChar);                  {Converts Buffer to a Pascal-style string}
  FreeMem(BufferPWideChar, SizeInt);                  {Frees memory allocated to Buffer}
end;

Re: DataSet Refresh Breaks

Posted: Fri 22 Nov 2013 10:03
by MilanLepi
Exactly !

I picked the code, tried to adjust it, but I don't understand those memory stuff :(

Thanks a lot !

Re: DataSet Refresh Breaks

Posted: Fri 22 Nov 2013 10:21
by AndreyZ
You are welcome. If any other questions come up, please contact us.