求几个函数和过程的写法,最好是简单和复杂参半 希望有注释谢谢

解决方案 »

  1.   

    要将函数的输出到EDit里就可以了
    随便写
      

  2.   

    function GetStr:String;
    begin
      Result := 'abc';
    end;Edit1.Text := GetStr;
      

  3.   

    看看书吧,比如delphi5 开发人员指南
      

  4.   

    Edit1.Text := 'AAAA';
    这个算不算
      

  5.   

    稍复杂一点的
    Edit1.Text:=IntToStr(12345);
      

  6.   

    定义函数 funtion 函数名({参数}):返回值类型;
    function FUNC():string;//无参数函数
    begin
    end;function FUNC(const A:integer):string;//常数参数函数
    begin
    end;function FUNC(A:integer):string;//传值参数函数
    begin
    end;function FUNC(var A:integer):string;//传址参数函数
    begin
    end;
    调用 Edit1.Text:=FUNC();//无参数函数返回值Edit1.Text:=FUNC(1);//带参数函数返回值
      

  7.   

    好吧,再来个更复杂一点的SendMessage(Edit1.Handle, WM_SETTEXT, 0, Integer(PChar('12345')));
      

  8.   


    procedure swap(x, y: integer);
    begin
    x := x xor y;
    y := y xor x;
    x := x xor y;
    end;
      

  9.   

    Delphi 自带了好多函数的写法呢.自己看就行啊
      

  10.   

    定义函数 funtion 函数名({参数}):返回值类型;
    function FUNC():string;//无参数函数
    begin
    end;function FUNC(const A:integer):string;//常数参数函数
    begin
    end;function FUNC(A:integer):string;//传值参数函数
    begin
    end;function FUNC(var A:integer):string;//传址参数函数
    begin
    end;
    调用 Edit1.Text:=FUNC();//无参数函数返回值Edit1.Text:=FUNC(1);//带参数函数返回值还有
    function Func(out A:string):boolean;
    begin
    end;
    调用
    var
     str:string;
    if Func(str) then
     begin
      Edit1.Text:=str;
     end;
      

  11.   

    截取字符串中间字符串函数:
    function zj(str,start,stop:WideString):string;
    begin
    Result:=Copy(Copy(Copy(str,pos(start,str)+length(start),length(str)),0,Length(str)),0,Pos(stop,Copy(Copy(str,pos(start,str)+length(start),length(str)),0,Length(str)))-1);
    end;
      

  12.   

    function IntToStr(Value: Integer): string;
    //  FmtStr(Result, '%d', [Value]);
    asm
            PUSH    ESI
            MOV     ESI, ESP
            SUB     ESP, 16
            XOR     ECX, ECX       // base: 0 for signed decimal
            PUSH    EDX            // result ptr
            XOR     EDX, EDX       // zero filled field width: 0 for no leading zeros
            CALL    CvtInt
            MOV     EDX, ESI
            POP     EAX            // result ptr
    {$IF DEFINED(Unicode)}
            CALL    System.@UStrFromPCharLen
    {$ELSE}
            PUSH    DefaultSystemCodePage
            CALL    System.@LStrFromPCharLen
    {$IFEND}
            ADD     ESP, 16
            POP     ESI
    end;
      

  13.   

    按逗號分隔取值:function TRes_HrCq_HBD_F.ReturnBM(bm:string):string;
    var
      Temp:TStrings;
      i:Integer;
    begin
      Temp:=TStringList.Create;
      Result:='';
      try
        Temp.DelimitedText:=bm;
        Temp.Delimiter:=',';
        for i:=0 to Temp.Count -1 do
          Result:=Result+QuotedStr(Temp[i])+',';
        Result:=Copy(Result,1,Length(Result)-1);
      finally
        Temp.Free;
      end;
    end;
      

  14.   

    access數據庫插入記錄函數:function Insdata(con:TADOConnection;StrWoSN,StrLotSN,StrNumberSN:string;ChBox:TCheckBox):Boolean;
    begin
      if not ChBox.Checked then
      begin
        try
          con.BeginTrans;
          con.Execute('insert into ServerData(NumberSN,WoSN,LotSN)values('+''''+StrNumberSN+''''+','+''''+StrWoSN+''''+','+''''+StrLotSN+''''+')');
          con.CommitTrans;
          Result:=True;
          except
            con.RollbackTrans;
            ShowMessage('數據記錄重復!請確認!!!');
            Result:=False;
          end;
          end
          else
          Result:=True;
      end;
      

  15.   

    生成BOM TREE過程:procedure TRES_BOM_VIEW_F.CREATETREEVIEWMODEL;
    var
      iLoop:Integer;
      Master,MasterNode:TTreeNode;
    begin
      adoq_getop.Close;
      //SELECT distinct PARN_TYP FROM WWW where parn_typ<>'.' and parn_typ is not null order by PARN_TYP desc
      adoq_getop.SQL.Text:='SELECT distinct PARN_TYP FROM WWW where parn_typ<>''.'' and parn_typ is not null order by PARN_TYP desc';
      adoq_getop.Open;
      adoq_getop.First;
      cx_TV.Items.BeginUpdate;
      cx_TV.Items.Clear;
      Master:=cx_TV.Items.Add(nil,'昆盈BOM表檢視');
      while not adoq_getop.Eof do
      begin
        if adoq_getop.FieldByName('PARN_TYP').AsString<>'' then
        begin
          Screen.Cursor:=crSQLWait;
          MasterNode:=cx_TV.Items.AddChild(Master,VarToStr(adoq_getop.FieldValues['PARN_TYP']));
          Application.ProcessMessages;
          qry_op.Close;
          qry_op.SQL.Text:='SELECT DISTINCT PARN_LITM FROM WWW WHERE PARN_TYP='''+ VarToStr(adoq_getop.FieldValues['PARN_TYP'])+''' GROUP BY PARN_LITM';
          qry_op.Open;
          for iLoop:=0 to qry_op.RecordCount -1 do
          begin
            cx_TV.Items.AddChild(MasterNode,VarToStr(qry_op.FieldValues['PARN_LITM']));
            qry_op.Next;
          end;
          Application.ProcessMessages;
          cx_TV.Items.EndUpdate;
          Screen.Cursor:=crDefault;
        end;
        adoq_getop.Next;
        Application.ProcessMessages;
      end;
     {
      ThreadTView:=cx_TV;
      ViewThread:=TExpandLH.Create;
      ViewThread.Resume;
      }
    end;調用:procedure TRES_BOM_VIEW_F.btnSB_SearchClick(Sender: TObject);
    begin
      inherited;
      try
        RES_LOADING_F:=TRES_LOADING_F.Create(Self);
        RES_LOADING_F.Label1.Caption:='正在檢索相關數據......';
        RES_LOADING_F.Show;
        RES_LOADING_F.Update;
        CREATETREEVIEWMODEL;
      finally
        RES_LOADING_F.Close;
      end;
    end;