typetbytebuff;= array of integers; Function ABC (A:integer): Tbytebuff;; var Temparr:tbytebuff; Begin SetLength (temparr,2); Temparr[0]: = A; TEMPARR[1]: = a + 10; Result:=temparr; End Procedure Tform1.button1click (Sender:tobject); var A:integer; Begin A: = 5; ShowMessage (INTTOSTR (ABC (a) [0])); 5//This returns the array showmessage (INTTOSTR (ABC (a) [1]) with such use; 15//This is used to return an array of end;function tfrmmain.commandframedata (Commandcode, Measuretype, Samplemode:byte; DataSize, Measuresum, Measureid:integer): Tbytebuff;vartempsendbuff,interabuff:tbytebuff; J,sum:integer;function Buildframedata (Commandcode, Measuretype, Samplemode:byte; DataSize, Measuresum, Measureid:integer): Tbytebuff; Group frame Data varsendbuff:tbytebuff;i:integer;beginsetlength (sendbuff,datasize);//fillchar (Sendbuff,sizeof (Sendbuff), 0 If commandcode=$01 then//Establish connection frame begin sendbuff[0]:=$01;end;if commandcode=$02 then//measurement task and parameter setting instruction begin if Measuret YPE=$03 then//digital measurement type begin Sendbuff[0]:=commaNdcode; instruction code sendbuff[1]:=measuresum; The number of Sendbuff[2]:=measureid is measured; Measurement ID sendbuff[3]:=measuretype; Measurement type sendbuff[5]:=dmeasureparam.dchannelnum; Digital channel number sendbuff[6]:=dmeasureparam.pulsepercir[0]; Number of pulses per lap sendbuff[7]:=dmeasureparam.pulsepercir[1]; Sendbuff[8]:=dmeasureparam.frequencycoefficient; Crossover factor sendbuff[4]:=sizeof (Sendbuff[5]) +sizeof (sendbuff[6]) +sizeof (sendbuff[7]) +sizeof (sendbuff[8]); Measurement parameter length end else begin sendbuff[0]:=commandcode; instruction code sendbuff[1]:=measuresum; The number of Sendbuff[2]:=measureid is measured; Measurement ID sendbuff[3]:=measuretype; If ameasureparam.samplemode=$00 then begin sendbuff[5]:=ameasureparam.achannelnum; Analog channel number Sendbuff[6]:=ameasureparam.dchannelnum; Digital channel number sendbuff[7]:=ameasureparam.nodenumpercir[0]; Capture points per lap Sendbuff[8]:=ameasureparam.nodenUMPERCIR[1]; SENDBUFF[9]:=AMEASUREPARAM.PULSEPERCIR[0]; Number of pulses per lap sendbuff[10]:=ameasureparam.pulsepercir[1]; Sendbuff[11]:=ameasureparam.choserange; Range selection sendbuff[4]:=sizeof (sendbuff[5]) +sizeof (sendbuff[6]) +sizeof (sendbuff[7]) +sizeof (sendbuff[8]) +SizeOf ( SENDBUFF[9]) +sizeof (sendbuff[10]) +sizeof (sendbuff[11]); measurement parameter length end; If ameasureparam.samplemode=$01 then begin sendbuff[5]:=ameasureparam.achannelnum; Analog channel number sendbuff[6]:=ameasureparam.samplerate[0]; Sampling rate sendbuff[7]:=ameasureparam.samplerate[1]; SENDBUFF[8]:=AMEASUREPARAM.SAMPLERATE[2]; SENDBUFF[9]:=AMEASUREPARAM.SAMPLERATE[3]; Sendbuff[10]:=ameasureparam.saveletter; Sendbuff[4]:=sizeof (Sendbuff[5]) +sizeof (sendbuff[6]) +sizeof (sendbuff[7]) +sizeof (sendbuff[8]) +SizeOf (sendbuff[9 ]) +sizeof (sendbuff[10]); End End;end; Result:=sendbuff;end; Beginsum:=0;interabuff:=buildframedata (Commandcode, Measuretype, Samplemode, DataSize, MeasureSum, MeasureID); SetLength (tempsendbufF,sizeof (Interabuff) +6); tempsendbuff[0]:=$7e;tempsendbuff[1]:=sizeof (Interabuff) +2;for J: = 0 to Sizeof (InteraBuff) -1 Dobegin tempsendbuff[2+j]:=interabuff[j]; sum:=sum+interabuff[j];end;tempsendbuff[3+j]:= (sum mod 65535); tempsendbuff[4+j]:=$7f; Result:=tempsendbuff; End
An easy-to-use array definition method in Delphi and using source code for nested functions