工具代码备忘

1、处理以逗号分隔的长字符串。

方法一:

procedure Str_Tools;
var
    TmpList:TStringList;
    IIndex:Integer;
    MUSVOL:String;
begin
    MUSVOL:='0,2,4,6,8,10';
    TmpList:=TStringList.Create;
    try
        while Pos(',',MUSVOL)>0 do
        begin
            IIndex:=Pos(',',MUSVOL);
            TmpList.Add(Copy(MUSVOL,1,IIndex-1));
            Delete(MUSVOL,1,IIndex);
        end;
        TmpList.Add(MUSVOL);
        showmessage(TmpList.Strings[1]);
   finally
        TmpList.free;
   end;
end;


方法二:

procedure Str_Tools2;
var
    I:integer;
    bol:Boolean;
    MUSLIST:Tstringlist;
    Dsp_MusicVol:array [0..6]of integer;
begin
    try
    	MUSLIST:=Tstringlist.Create;
	MUSLIST.CommaText:='1,3,5,7,9,11';
        for i:=0 to 6 do
        begin
           if (MUSLIST.Count>=i-1) then  Dsp_MusicVol[i]:=strtoint(MUSLIST[i]);
           showmessage(Dsp_MusicVol[i]);
        end;
        
    finally
        MUSLIST.free;
    end;

end;

 

2、程序窗体最大化、组件居中显示代码

程序主窗体放置Tpanel组件、把Align属性设置为alclient,在panel的Resize事件中写

procedure TFrm_AddNewUser.Panel1Resize(Sender: TObject);
begin
    Panel2.Left := round((Width - 8 - Panel2.Width) / 2);      //常量8用于处理边界问题
     Panel2.Top := round((Height - 8 - Panel2.Height) / 2);
end;


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值