troubleshooting Question

The proper way

Avatar of QC20N
QC20NFlag for Denmark asked on
Delphi
4 Comments1 Solution274 ViewsLast Modified:
I have this code that I hope some can help me to write proper way. The code does what it should do, but I'm not sure if this is the proper way. Hopefully some of it could be rewrite to a function.

Thank you
procedure TForm1.ADInfoUpdate;
var User : IADsuser; LineList : TStringList; sADPath, sdesc : string; Query : TADOQuery; VarArray, Value : Variant; i, HighBound : integer; Updated: boolean;
begin
  Updated := false;
  ADOQuery1.SQL.Clear;
  ADOQuery1.SQL.Add('SELECT REASON, ADPATH FROM USERINACTIVE WHERE ADUPDATE = :ADUpdate');
  ADOQuery1.Parameters.ParamByName('ADUpdate').Value := False;
  ADOQuery1.Open;
  try
    while not ADOQuery1.Eof do
    begin
      try
        if SUCCEEDED(ADsGetObject(ADOQuery1.FieldByName('ADPATH').AsString, IADsUser, User)) then
        begin
          LineList := TStringList.Create;
          LineList.Delimiter := ',';
          LineList.CaseSensitive := True;
          try
            sdesc := User.Description;
            try
              LineList.DelimitedText := Uppercase(StringReplace(sDesc,' ','_',[rfReplaceAll]));
              for I := 0 to LineList.Count - 1 do
              begin
                if pos('BOSS',LineList[i]) <> 0 then
                begin
                  LineList[i] := StringReplace('BOSS: ' + ADOQuery1.FieldByName('REASON').AsString,' ','_',[rfReplaceAll]);
                  Updated := true;
                end;
              end;
              for I := 0 to LineList.Count - 1 do
              begin
                if pos('_',LineList[i]) = 0 then
                  LineList[i] := QuotedStr(LineList[i])
                else
                  LineList[i] := StringReplace(LineList[i],'_',' ',[rfReplaceAll]);
              end;
              User.Description := Linelist.DelimitedText;
              User.SetInfo;
            finally
              User := nil;
              LineList.Free;
            end;
          except
            user.Description := '"BOSS: ' + ADOQuery1.FieldByName('REASON').AsString+'"';
            User.SetInfo;
          end;
        end;
      except
        on EOleException do
        begin
          // ShowMessage('Test');
        end;
      end;
      ADOQuery1.Next;
    end;
  finally
    ADOQuery1.Close;
  end;
end;
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros