Solved

DataSet Before Post event

Posted on 2000-02-28
7
408 Views
Last Modified: 2010-04-04
Is it possible to access the existing value of a field(ie the value before this pending post)within this event handler WITHOUT enabling cached updates?

If so, how?

Many thanks
0
Comment
Question by:dasmi
7 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 2564753
what about the BeforePost event?

Zif.
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2564991
If you directly modifying field, for example by TDBEdit, last field value became unavalable. You cannot access last field value by simply way. You can try extract it from database by another Query only :(
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2565004
Hmmm... I forget about.....
.... if you use IBX components, it possible.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 2565011
listening . . .
0
 
LVL 2

Accepted Solution

by:
kubeerja earned 50 total points
ID: 2566330
a simple way is to save it in a variable before Edit and check that value before post.

other wise you need to extract the value from the Active buffer of the DataSet then you can try this function

function TForm1.fDbiGetField(hTmpCur: hDBICur; FieldNo: Word): Variant;

var
  Props: CURProps;
  pFlds, pOldFlds: pFLDDesc;
  pRecBuf: pBYTE;
  FieldString: string;
  FieldINT16: Smallint;
  FieldINT32: Longint;
  FieldUINT16: Word;
  FieldFLOAT: Double;
  Blank: LongBool;
begin
  if (FieldNo < 1) then
    raise EDatabaseError.Create('Field number index is 1 based');

  Check(DbiGetCursorProps(hTmpCur, Props));
  pFlds := AllocMem(Props.iFields * sizeof(FLDDesc));
  pOldFlds := pFlds;

  pRecBuf := AllocMem(Props.iRecBufSize * sizeof(BYTE));
  try
    Check(DbiGetFieldDescs(hTmpCur, pFlds));
    Inc(pFlds, FieldNo - 1);
    Check(DbiGetRecord(hTmpCur, dbiNOLOCK, pRecBuf, nil));
    case pFlds.iFldType of
      fldDATE, fldTIME, fldTIMESTAMP, fldUNKNOWN, fldBLOB, fldBOOL, fldBCD:
        raise EDBEngineError.Create(DBIERR_NOTSUPPORTED);
      fldZSTRING:
      begin
        SetLength(FieldString, pFlds.iUnits1 + 1);

        Check(DbiGetField(hTmpCur, FieldNo, pRecBuf,
          pBYTE(PChar(FieldString)), Blank));
        SetLength(FieldString, StrLen(PChar(FieldString)));
        Result := FieldString;
      end;
      fldINT16:
      begin
        Check(DbiGetField(hTmpCur, FieldNo, pRecBuf, pBYTE(@FieldINT16),
          Blank));
        Result := FieldINT16;
      end;
      fldUINT16:
      begin
        Check(DbiGetField(hTmpCur, FieldNo, pRecBuf, pBYTE(@FieldUINT16),

          Blank));
        Result := FieldUINT16;
      end;
      fldFLOAT:
      begin
        Check(DbiGetField(hTmpCur, FieldNo, pRecBuf, pBYTE(@FieldFLOAT),
          Blank));
        Result := FieldFLOAT;
      end;
      fldINT32, fldUINT32:
      begin
        Check(DbiGetField(hTmpCur, FieldNo, pRecBuf, pBYTE(@FieldINT32),
          Blank));
        Result := FieldINT32;
      end;
    end;
  finally
    FreeMem(pOldFlds, Props.iFields * sizeof(FLDDesc));
    FreeMem(pRecBuf, Props.iRecBufSize * sizeof(BYTE));
  end;
end;

you can call it like this

Label4.Caption:=VarToStr(fDbiGetField(Table1.Handle,Table1.FieldByName('tname').Index + 1)) ;
0
 

Author Comment

by:dasmi
ID: 2566674
It works.

It is a solution which demonstrates a good knowledge of the underlying DB engine. What a great pity it is necessary to go to these lengths to simply get the existing field value(s).

Thank you very much for your prompt response with a fully working solution. I am impressed with the experts exchange service in general, and with kubeerja in particular.

0
 
LVL 2

Expert Comment

by:kubeerja
ID: 2566892
Thank you, :-)
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question