DataSet Refresh Breaks

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
MilanLepi
Posts: 2
Joined: Wed 20 Nov 2013 19:36

DataSet Refresh Breaks

Post by MilanLepi » Wed 20 Nov 2013 19:49

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

AndreyZ

Re: DataSet Refresh Breaks

Post by AndreyZ » Thu 21 Nov 2013 11:57

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;

MilanLepi
Posts: 2
Joined: Wed 20 Nov 2013 19:36

Re: DataSet Refresh Breaks

Post by MilanLepi » Fri 22 Nov 2013 10:03

Exactly !

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

Thanks a lot !

AndreyZ

Re: DataSet Refresh Breaks

Post by AndreyZ » Fri 22 Nov 2013 10:21

You are welcome. If any other questions come up, please contact us.

Post Reply