zoukankan      html  css  js  c++  java
  • Memo 的当前行、当前列与当前字符

    procedure TForm1.Memo1Click(Sender: TObject);
    begin
      Text := Format('当前列:%d, 当前行:%d', [Memo1.CaretPos.X, Memo1.CaretPos.Y]);
    end;
    
    //用 API 实现
    procedure TForm1.Memo1Click(Sender: TObject);
    var
      LineY,LineX: Integer;
    begin
      LineY := SendMessage(Memo1.Handle,EM_LINEFROMCHAR,Memo1.SelStart,0);
      LineX := SendMessage(Memo1.Handle,EM_LINEINDEX,LineY,0);
      Text :=  '当前行:' + IntToStr(LineY) + '; ' +                  //0开始
              '当前列:' + IntToStr(Memo1.SelStart - LineX) + '; '//0开始
              '当前字符:' + IntToStr(Memo1.SelStart) + '. ';          //包括#13#10
    end;

    //统计字数
    
    //添加 Memo1、Label1、Label2、还有Button1
    procedure TForm1.Button1Click(Sender: TObject);
    var
      s: string;
      i,sum,e,c,t: Integer;
    begin
      s := Memo1.Text;
      e := 0;
      c := 0;
      sum := Length(s);
    
      for i := 0 to sum do
      begin
        if (Ord(s[i]) >= 33) and (Ord(s[i]) <= 126) then
        begin
          Inc(e);
          Label1.Caption := '字母数: ' + IntToStr(e);
        end;
    
        if Ord(s[i]) >= 127 then
        begin
          Inc(c);
          Label2.Caption := '汉字数: ' + IntToStr(c div 2);
        end;
      end;
    end;
    
  • 相关阅读:
    windows常用快捷键
    【Linux】查看系统位数
    【Centos】yum 安装mariaDB
    【Centos7 GRUB】修改开机等待时间
    Shell脚本编写规范
    【Shell Basic】source . 与 bash sh 的区别
    linux防火墙之 ufw
    【HotSpot】jps命令行详解
    【Ubuntu 16】网络配置文件
    【刷题】BZOJ 2179 FFT快速傅立叶
  • 原文地址:https://www.cnblogs.com/qingsong/p/3515082.html
Copyright © 2011-2022 走看看