Page 1 of 1

Recordset

Posted: Fri 12 Oct 2007 18:02
by djedai
Hi. I have one question.. for u components.
Standart components query have parammetr Recordset
i ask as MyDaC (Mysql) Query not have this parammetr..
well how i can use this commponents

Posted: Sat 13 Oct 2007 08:22
by djedai
Hey SOmeone Can Help me or all in this forum dead.

wait...

Posted: Sat 13 Oct 2007 20:35
by eduardosic
djedai wrote:Hey SOmeone Can Help me or all in this forum dead.
wait.. be patient..

Posted: Mon 15 Oct 2007 07:10
by Antaeus
Just assign a command to the SQL property, and call Open to get a recordset. The command must return data. You can link with TMyQuery a DB-aware control like TDBGrid, or a set of controls like TDBEdit to browse and edit data. To access data programmatically, use the FieldByName property. To scroll through the recordset use Next, Prior, First, Last methods.
For example see demo projects included in MyDAC. Also see the description of properties and methods mentioned above and others in the Delphi help.

Posted: Mon 15 Oct 2007 09:30
by djedai

Code: Select all

procedure TForm1.SetCurrentAccessLevel;
var
 i:integer;
 AccLvl:integer;
begin
 if not flSelected then exit;
 Query .Close;
 Query .SQL.Text:='SELECT [User],[Password],[AccessLevel] FROM One WHERE [User]='''+CurName+'''';
 try
  Query .Open;
 except
 end;
 if Query .RecordCount = 0 then
  ShowMessage('Нет такого юзера.')
 else
  try
   AccLvl:=Query .Recordset.Collect[2];
   if string(Query .Recordset.Collect[1])=CurPass then
     for i:=0 to Form1.ComponentCount-1 do
      begin
       if Form1.Components[i].Tag= 0 then continue else
       if (Form1.Components[i] is TControl)then (Form1.Components[i] as TControl).Enabled :=AccLvl>=Form1.Components[i].Tag
       else if (Form1.Components[i] is TMenuItem)then (Form1.Components[i] as TMenuItem).Enabled :=AccLvl>=Form1.Components[i].Tag;
      end
    else ShowMessage('Неправильный пароль.');
  except
   ShowMessage('Неудачно.');
  end;
  flSelected:=false;
end;
this exemple for standart components Delphi 7

try this..

Posted: Mon 15 Oct 2007 10:11
by eduardosic
try this..

Code: Select all

procedure TForm1.SetCurrentAccessLevel;
var
 i:integer;
 AccLvl:integer;
begin
     if not flSelected then 
      exit;
     Query .Close;
     Query .SQL.Text:='SELECT User, Password, AccessLevel FROM One WHERE User='''+CurName+'''';
      try
        Query .Open;
      except
      end;
     
      if Query .RecordCount = 0 then
        ShowMessage('Нет такого юзера.')
      else
        try
          AccLvl := Query.FieldByName( 'AccessLevel' ).AsInteger;
          if Query.FieldByName( 'Password'  ).AsString =CurPass then
            for i:=0 to Form1.ComponentCount-1 do
            begin
               if Form1.Components[i].Tag= 0 then 
                 continue 
               else
                 if (Form1.Components[i] is TControl) then
                  (Form1.Components[i] as TControl).Enabled :=AccLvl>=Form1.Components[i].Tag
       else if (Form1.Components[i] is TMenuItem)then (Form1.Components[i] as TMenuItem).Enabled :=AccLvl>=Form1.Components[i].Tag;
      end
    else ShowMessage('Неправильный пароль.');
  except
   ShowMessage('Неудачно.');
  end;
  flSelected:=false;
end;

Posted: Mon 15 Oct 2007 10:52
by djedai
OK All thx this Varian Work good. :)