From e1f761a7798a3e9cab9288efd4f8384effd7bfd4 Mon Sep 17 00:00:00 2001 From: SeedList Date: Tue, 20 May 2025 11:14:59 +0800 Subject: [PATCH] vault backup: 2025-05-20 11:14:59 --- .../相关操作/4.0-other/999.Delphi脚本记录.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/SanPinPLM/相关操作/4.0-other/999.Delphi脚本记录.md b/SanPinPLM/相关操作/4.0-other/999.Delphi脚本记录.md index 16252a5a..38ebfcad 100644 --- a/SanPinPLM/相关操作/4.0-other/999.Delphi脚本记录.md +++ b/SanPinPLM/相关操作/4.0-other/999.Delphi脚本记录.md @@ -463,4 +463,30 @@ begin if A.itemindex <> -1 then B.Text := A.Text; end. +``` + +## 截取指定字符前的字符串 + +当 `cbxusr_pinpai` 未被勾选时,只保留 `fedtItemCode` 中 `-` 之前的部分 + +```Delphi +uses + MyClass, Variables, BaseUtil, CommonFunc, DataConst, CFFrm, CFSimplePropFrm, + Forms, StdCtrls, Variants, SysUtils, Classes, Controls, Dialogs, + CHostIntf, ProductClas, DocClas, LoginClas, VirtualTrees, CEntClas, PathClas; + +var + DashPos: Integer; // 存储 "-" 的位置 +begin + // 检查条件:itemcode 包含 "-" 并且 cbxusr_pinpai 未勾选 + if (Pos('-', fedtItemCode.Text) > 0) and (cbxusr_pinpai.Checked = false) then + begin + // 找到 "-" 的位置 + DashPos := Pos('-', fedtItemCode.Text); + // 只保留 "-" 之前的部分 + fedtItemCode.Text := Copy(fedtItemCode.Text, 1, DashPos - 1); + end; + if cbxusr_pinpai.checked = false then + fedtusr_gongyingshang.itemindex := -1; +end. ``` \ No newline at end of file